Hey i’m working on a class called a “Body” which holds shapes and sprites together as one object. I would like to get into the source code and add a new overload RenderWindow’s Draw() function, so this new object can be taken in and drawn easily. How do i do this?
I’m currently using
- Windows 7
- SFML 1.6
- Newly msVS++ 2010 compiled static debug libraries and dlls
- original include folder
EDIT:
I also found this in the Drawable.hpp header:
private :
friend class RenderTarget;
////////////////////////////////////////////////////////////
/// Draw the object into the specified window
///
/// \param Target : Target into which render the object
///
////////////////////////////////////////////////////////////
void Draw(RenderTarget& Target) const;
////////////////////////////////////////////////////////////
/// Render the specific geometry of the object
///
/// \param Target : Target into which render the object
///
////////////////////////////////////////////////////////////
virtual void Render(RenderTarget& Target) const = 0;
but i can’t figure out where the full code of each function is, just the declarations.
I didn’t find a mini tutorial there either unfortunately…
Note:
Before you derive from and implemented your own Drawable, you may want to consider if you need to do it at all. The author of SFML has stated that
sf::Drawablewas not initially meant to be subclassed outside of SFML.That aside,
For SFML 1.6:
It appears that all you need to do is derive your class from
sf::Drawable, and then implement a virtualRenderfunction.An example of this can be found on the SFML forums.
For SFML 2.0:
The
Drawableheader file from SFML contains comments that describe how to derive your ownDrawableclasses. You do not need to modify the SFML source code to create new Drawables.It also includes a simple example:
This example may apply to SFML 2.0, but if you inspect the
Drawable.hppfrom whatever version of SFML you have it should contain a similar example.