#include "cocos2d.h"
class Creature : public cocos2d::Node
{
public:
Creature();
~Creature();
cocos2d::Vec2 get_position();
int get_x();
int get_y();
void set_y_position(const int);
void set_x_position(const int);
void set_position(const cocos2d::Vec2);
void draw();
private:
cocos2d::Sprite* m_creature_sprite;
cocos2d::Vec2 m_position;
};
I am fairly new and do not know the best practices with the engine. What do I need to do in the overridden cocos2d::Node draw method above to ensure that my class gets drawn? Is doing the above even recommended, or should I use a factory that returns a cocos2d::Sprite*?
If you actually want to draw m_creature_sprite, you do not have to do anything special. Just be sure the sprite is on the node’s hierarchy.
For example:
in Creature constructor:
m_creature_sprite = Sprite::create(“my_sprite.png”);
addChild(m_creature_sprite);
thats it!
if you really want to make a custom draw method for your class, then follow slackmoehrle’s advice
Slackmoehrle for overriding the draw method I knew to do that, I just didn’t know if there was something special I needed to do. I didn’t read all the class documentation and didn’t know that I inherited the get and set position functions, thanks for that heads up.
Dredok I apologize for the confusing title. Adding the sprite as a child in the constructor worked, thank you. I didn’t think it could be something that easy which is why I was wanting to override the draw method.