CCAnimation problem

CCAnimation problem
0.0 0


I want to make animation of sprite:

walkAnim = CCAnimation::create(); walkAnim->setDelayPerUnit(0.1f);
CCSpriteFrame* pFrame; CCRect rect(0, 0, 32, 32); pFrame = CCSpriteFrame::create("hero0.png", rect); walkAnim->addSpriteFrame(pFrame); pFrame = CCSpriteFrame::create("hero1.png", rect); walkAnim->addSpriteFrame(pFrame); pFrame = CCSpriteFrame::create("hero2.png", rect); walkAnim->addSpriteFrame(pFrame); pFrame = CCSpriteFrame::create("hero3.png", rect); walkAnim->addSpriteFrame(pFrame); pFrame = CCSpriteFrame::create("hero4.png", rect); walkAnim->addSpriteFrame(pFrame); pFrame = CCSpriteFrame::create("hero5.png", rect); walkAnim->addSpriteFrame(pFrame); walk = CCAnimate::create(walkAnim);

then i call

and have “corruption of the heap” error;

so while debug every pFrame have
m_pobTexture = 0x00000000 {m_bPVRHaveAlphaPremultiplied=? m_ePixelFormat=? m_uPixelsWide=??? …}
m_strTextureFilename = “hero0.png”

Help me, please.


Hi Thanks for this code, it helped me to solve my own problem.

I used a slightly different code than yours, I didn’t used pFrame = CCSpriteFrame::create(“hero0.png”, rect);
but had no error. Maybe the problem is with your files.

here is my working code:

charAnimation = CCAnimation::create( );
charAnimation > setDelayPerUnit;
> setLoops( INFINITY ); // looping the animation, working so far until I closed the iOS simulator (1 hour). if anyone knows a better way, please let me know.

charAnimation > addSpriteFrameWithFileName;
> addSpriteFrameWithFileName( “frame2.png” );
charAnimation > addSpriteFrameWithFileName;
> addSpriteFrameWithFileName( “frame4.png” );

theAnimation = CCAnimate::create( charAnimation );
theAnimation > initWithAnimation;
character = CCSprite::create;
> setPosition( ccp( 100, 100 ));

this > addChild;
> runAction( theAnimation );

sorry for the format, “it’s my first day”.