[SOLVED] CCAnimation: problem and solution

I was trying to translate it from objective-C (Book Learning Cocos2D - Chapter 2), but it didn’t work.
The code didn’t crash, but the animation didn’t work.

CCAnimation* animation = CCAnimation::animation();
animation~~>addFrameWithFileName;
animation~~>addFrameWithFileName(“an1_anim3.png”);
animation~~>addFrameWithFileName;
CCAnimate animate = CCAnimate::actionWithAnimation;
CCAction
act = CCRepeatForever::actionWithAction;
sprite~~>runAction(act);

So, I added some code in CCAnimation.cpp and CCAnimation.h:

CCAnimation.h

bool init(float delay);
static CCAnimation* animation(float delay);

CCAnimation.cpp

bool CCAnimation::init(float delay)
{
return initWithFrames(NULL, delay);
}
CCAnimation* CCAnimation::animation(float delay)
{
CCAnimation **pAnimation = new CCAnimation;
pAnimation~~>init;
pAnimation~~>autorelease;
return pAnimation;
}

In my code, I changed
CCAnimation** animation = CCAnimation::animation();
to
CCAnimation* animation = CCAnimation::animation(0.3f);

Then… everything is working fine.
Was I doing anything wrong?
I hope it could help us.
Should we put it in Cocos2D code?

Having very similar problems with CCAnimation.

CCAnimation *animation = NULL; animation = CCAnimation::animation(); CCMutableArray<CCSpriteFrame*>* arrAux = new CCMutableArray<CCSpriteFrame*>(); arrAux->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("Example_0.png")); animation->initWithFrames(arrAux);

When doing the initWithFrames function, it returns a “Unhandled exception at 0x778715ee in FvZ.win32.exe: 0xC0000005: Access violation.”

I’d rather avoid having to rebuild the library to add the hack Jefferson provided, which looks like a coincidental fix if anything.
Any solutions? Thank you.

Jaime, please try this. It’s working for me

CCSpriteFrameCache::sharedSpriteFrameCache()>addSpriteFramesWithFile;
CCAnimation* animation = CCAnimation::animation;
char frameName[7];
for
{
sprintf;
CCSpriteFrame* pFrame = CCSpriteFrameCache::sharedSpriteFrameCache
>spriteFrameByName;
animation~~>addFrame;
}
CCSprite *spriteAnim = CCSprite::spriteWithSpriteFrameName;
spriteAnim~~>setPosition( ccp(100, 200) );
CCAnimate animate = CCAnimate::actionWithAnimation;
CCAction
act = CCRepeatForever::actionWithAction(animate);
spriteAnim~~>runAction;
this~~>addChild(spriteAnim, 2);

Alexander Tkachenko

I was trying to use sharedSpriteFrameCache (some examples did’nt work) and finally you taught me. Thanks a lot.

Jaime, if you don’t want to use my add-on, you can use Alexander’s code changing this line:

CCAnimation* animation = CCAnimation::animation(0.2f);

to

CCAnimation* animation = CCAnimation::animation();
animation->setDelay(0.1f);

Thank you all for your replies, I solved it by disposing of the .lib file I had of cocos and recompiling the library. It works now with the new .lib.