SFML community forums
Help => General => Topic started by: bobbyport on June 29, 2009, 02:32:30 am
-
This is what I've got right now: http://codepad.org/udmkNHX9
I would like the node object to be responsible for drawing its sprite image as well as its origin (using a circle).
I could easily have it draw multiple sprites (one for its actual image the other for its origin) but I would prefer using a shape.
When I try getting the node class to inherit from sf::Sprite and sf::Shape I receive the following error:
error C2594: 'argument' : ambiguous conversions from 'Node' to 'const sf::Drawable &'
-
sf::Sprite and sf::Shape both inherit from sf::Drawable, that's why the compiler is confused.
You shouldn't inherit from them. Your class is not a sprite or a shape, it is implemented using a sprite and a shape. Public inheritance in C++ is a strong design choice, it should really be used carefully.
But what you can do is inherit from sf::Drawable and override the Render function to draw your sprite and shape.
-
Could you give me an example?
The sf::Drawable does not have a Render method.
-
It does.
class Node : public sf::Drawable
{
virtual void Render(RenderTarget& Target) const
{
Target.Draw(mySprite);
Target.Draw(myShape);
}
sf::Sprite mySprite;
sf::Shape myShape;
};
Node node;
window.Draw(node);