inheriting from CCSprite to create animation

Hello i try to create simple sprite that will hold frame animation but i must doing something wrong here
i followed the tutorial from here [[http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Animations]]
the first part . i didn’t do the secound part becouse i didint found any free tool that export to plist but this is another problem .
any way here is my code i invoke it from the bool HelloWorld::init()
but i don’t see any thing in the screen

bool HelloWorld::init()
{
...
...
...
do 
    {

m_AngelSprite =  new AngelSprite();
        CC_BREAK_IF(! m_AngelSprite);
        m_AngelSprite->setPosition(ccp(m_AngelSprite->getContentSize().width/2,iHeight/2));
        this->addChild(m_AngelSprite);
  bRet = true;
    } while (0);
}



#ifndef __ANGELSPRITE_H__
#define __ANGELSPRITE_H__

#include "cocos2d.h"

class AngelSprite : public cocos2d::CCSprite
{
    public :
        virtual void draw();
        AngelSprite();
        //virtual ~AngelSprite(){};
        //virtual void draw(void);
        void runAnimation();


    private:
        cocos2d::CCAnimation *animation; 
        cocos2d::CCAnimate *action;
        void playImageAnim();
        void loadImgs();


};



#endif

#include "AngelSprite.h"


AngelSprite::AngelSprite()
{
    animation = cocos2d::CCAnimation::create();
    loadImgs();
    playImageAnim();
    action =  cocos2d::CCAnimate::create(animation);
}


void AngelSprite::draw()
{
    //CCSprite::draw();
}


void AngelSprite::loadImgs()
{
    for(int i=1;i<=2;i++)
    {
        char szImageFileName[128] = {0};
        sprintf(szImageFileName, "angel_%d.png",i);
        animation->addSpriteFrameWithFileName(szImageFileName);  
    }
}

void AngelSprite::playImageAnim()
{
    animation->setDelayPerUnit(0.8f / 2.0f); // This animation contains 14 frames, will continuous 2.8 seconds.
    animation->setRestoreOriginalFrame(true); // Return to the 1st frame after the 14th frame is played. 
}

void AngelSprite::runAnimation()
{
    this->runAction(action);  // run action on sprite object
}

What OS are you building on? TexturePacker is free and works fine.

Anyway, you overridden the draw* method which does the rendering.
What I usually do when subclassing, is to subclass CCNode and just have a CCSprite member on it.
<pre>
class Angel : public cocos2d::CCNode {
private:
cocos2d::CCSprite
m_Sprite;

public:
cocos2d::CCSprite * getSprite();
}

I would then use \*Angel::getSprite()\* if I want to control the sprite outside of the class.

If you want to create a sprite animation where you provide the frames manually, then subclass from CCSprite and set the displayFrame at each key frame update.

That’s all there is to it.

`Jacob Anderson
can you please give me short code spinet to understand what you mean ?

`Lance Gray
thanks for the replay , what is better do you think in such cases , when you what to build custom sprite ?
to subclass node or sprite

@Lance Gray
about TexturePacker i don’t understand here something basic
the txt file it creates its content dosnt look like the xml i see in .plist files for example in animations/animations-2.plist

meir meiry wrote:

`Lance Gray
thanks for the replay , what is better do you think in such cases , when you what to build custom sprite ?
to subclass node or sprite
I’ve always used to inherit CCNode and it works. I sticked to it ever since.

`Lance Gray
about TexturePacker i don’t understand here something basic
the txt file it creates its content dosnt look like the xml i see in .plist files for example in animations/animations-2.plist
Did you select cocos2d as output? Can you post screenshot?

meir meiry wrote:

but i don’t see any thing in the screen

You are not getting any image on screen because you havent initialized the base class. Call CCSprite::initWith…() method.