[Solved] Sprite Animation stopping

++Hello,

i’v got a bad problem, that i’v not been able to solve in 2 Days.

I did use about 4 or 5 kind of code to create an AnimateAction out of Sprites and theres no difference between them :smiley:

Problem Solved
See: http://www.cocos2d-x.org/boards/6/topics/18107?r=18138#message-18138

my code atm:

mMann->stopAllActions(); char*images[] = {"bier1.png", "bier2.png", "bier1.png", "mann.png"};

CCAnimation* animation = CCAnimation::create(); animation->addSpriteFrameWithFileName(images[0]); animation->addSpriteFrameWithFileName(images[1]); animation->addSpriteFrameWithFileName(images[2]); animation->addSpriteFrameWithFileName(images[3]);

animation->setDelayPerUnit(4.0f / 4.0f); animation->setRestoreOriginalFrame(true);

CCAnimate* action = CCAnimate::create(animation); //mMann->runAction(CCSequence::create(action, NULL)); mMann->runAction(action);

The Problem:

The Animation starts, the first sprite “bier1.png” is always displayed, no problem there.
But, then it’s random if the animation goes on or not.

Sometimes it gets until the second “bier1” or stops at “bier2” or in some cases, 1 out of 20, it gets to “mann.png”.

Im using cocos2dx 2.0.3 on Windows.
I didn’t test it on IOS or Android yet.

I hope you can help me.

PS:

Animations working fine. I made some, like rotating, particles with cocosbuilder.
I Import this node (CustomLayer) add it to a new scene and run it.

Then i some minor things and it runs, when i click on a button the above code is run.

Have you tried seeing if the animation works when you repeat for ever,? Also see if it helps if you get rid if the restore original frame call.

Jeah i have tried Not using RestoreOriginal and i think also Repeating it, ill try the Repeating once more, but that wont help describing the Problem, does it.?
I hate Auto completion, does Not work with 2 languages at once…

Next Update,
I did code some minor counter to see how far the animation runs.

In my update:

if(animationStart){
    counter+=dt;
    if(mMann->numberOfRunningActions()==0){
        animationStart=false;
        CCLOG("%f",counter);
        counter = 0.0f;
    }
}

And my AnimationStart code:

mMann->stopAllActions();

char*images[] = {"bier1.png", "bier2.png", "bier1.png", "mann.png"};

CCAnimation* animation = CCAnimation::create();

animation->addSpriteFrameWithFileName(images[0]);
animation->addSpriteFrameWithFileName(images[1]);
animation->addSpriteFrameWithFileName(images[2]);
animation->addSpriteFrameWithFileName(images[3]);

animation->setDelayPerUnit(4.0f / 4.0f);
//animation->setRestoreOriginalFrame(true);

CCAnimate* action = CCAnimate::create(animation);
//mMann->runAction(CCSequence::create(action, NULL));
mMann->runAction(action);
animationStart=true;

Result:
1.9
2.1
1.8
2.6
2.3
2.9
2.0
2.7
3.5
2.8

If I restart and do it again, the numbers are NOT the same. Its random.

As Info:
I did try using a plist to load those images, no difference.
I tried storing them in an array first then loading the animation with it, no difference.
I did try loading the animation storing it in the animationCache and then loading from there, no difference.
i tried using a sequence of small 1 Image changing actions in a row, no difference.

My opinion:
It may be my Layer/Node composition, => CocosBuilder.
In the example Code of cocos2dx they use an extra layer for Animations.
I’ll try that.

But don’t stop trying to help me. I really don’t think it’ll be so easy to solve that.

Problem Solved:

For everyone, I don’t now exactly if its CocosBuilder. But I do not have any other layer in my game by now.

If you make animations in Cocosbuilder, you set up a timeline and the length of this timeline.
If the timeline is over, it resets the animations and restarts them.

IF you now add animations to this Layer (from Code) this animations will be stopped at the end.

Solution:

It’s easy. just add a Layer to the CCNode on which you want the Animations.
Add your CCSprites (which will be animated by code) to this layer.
Animate them.

I did all this by code, it’s short.
You can add everything as CCSprite in CososBuilder and set them to not visible.
Because you will maybe need some indication points.

Then in Code you do following:

CCLayer *animLayer = CCLayer::create();
animLayer->setPosition(0.0f,0.0f);

mNode->addChild(animLayer);

mMann1 = CCSprite::create("mann.png");
mMann1->setPosition(mMann->getPosition());

animLayer->addChild(mMann1);

mNode is my biggest CCNode which I use to scale my complete Game without scaling the scene.
mMann is the CCSprite in CocosBuilder which tells me the position of the Mann.

animLayer is my new Layer in cocos2dx.
mMann1 is my animated character in cocos2dx.

Btw, this code isn’t perfect, it is testing code.