0

I created a CCAnimation as seen below. I tried lowering the delay to something below .05f and the animation now fails to complete! Its only 8 frames. I don't know if I am doing something wrong. At first I thought it was a memory leak and I was losing the action, so I assigned it to a strong property to test that, and still did it. I'm not sure how the delay could cause my animation to fail to finish. I am running in the simulator at 60 frames per sec.

Using Kobold 2.0.4

Can anyone help?

else if([model currentState] == PROCESSING_FIRST_ACTION)
        {
            CCDirector* director = [CCDirector sharedDirector];    // process model
            //Get the top left corner of the screen
            int screen_height = director.screenSizeAsPoint.y;
            int screen_width = director.screenSizeAsPoint.x;

            id attacker = [model attacker];
            id attackChoice = [attacker getRegisteredAttack];

            CCAction* attack = [model.resourceManager animation: @"simple-attack-frame"];
            CCSprite * attackSprite = [model.resourceManager sprite: @"simple-attack-frame-01"];

            attackSprite.position = ccp(screen_width - rxa(80), screen_height - rya(80));
            attackSprite.tag = 5;
            self.action = attack;

            CCNode * check = [self getChildByTag:5];

            if(check == nil)
            {
                [self addChild: attackSprite];
                [attackSprite runAction:attack];
            }
        }

resource manager:

-(id)animation: (NSString*)_resource
{
    NSMutableArray *frames = [NSMutableArray array];

    for(int i = 1; i <= 8; ++i)
    {
        [frames addObject:
         [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
          [NSString stringWithFormat:@"%@-0%d", _resource, i]]];
    }

    CCAnimation *animation = [CCAnimation animationWithSpriteFrames: frames delay:1/60];

    CCAction * action = [CCAnimate actionWithAnimation: animation];

    return action;

}
AwDogsGo2Heaven
  • 952
  • 11
  • 26
  • 1
    I've seen an issue like this, but in cocos2d v1.1. They changed something in the animation system, I didn't really understand the code, it seemed broken to me. The effect was that timings were off, and sometimes animations didn't play at all. I don't know if this change has been integrated to 2.0. You might want to try recreating the scenario in a vanilla cocos2d 2.0 project, then file a bug report. – CodeSmile Oct 20 '12 at 08:52
  • Oh this isn't good. I mean if I can't get an animation to work in a game, thats a game breaking bug =(. – AwDogsGo2Heaven Oct 20 '12 at 13:56
  • 1
    The animation is being stopped by the ActionManager because the time elapsed is greater than the duration. (isDone). I'm going to look deeper into it but I think the easiest solution is to overload isDone to be true only after showing the last frame. – AwDogsGo2Heaven Oct 20 '12 at 16:29

2 Answers2

1

In your line

CCAnimation *animation = [CCAnimation animationWithSpriteFrames: frames delay:1/60];

you're setting the delay to 1/60, but as 1 and 60 are both integers, 1/60 is 0. Try using 1.0f/60.0f and you'll get a floating point divide.

Paul Masri-Stone
  • 2,843
  • 3
  • 29
  • 51
  • That is right, I noticed that shortly after to... And it does work, unless the frame rate drops and then the same problem comes back with the animation not finishing. – AwDogsGo2Heaven Oct 22 '12 at 15:16
0

After digging around on the web I found a solution. I'm not the one who submitted this solution but I can attest that it fixed my problems:

https://github.com/cocos2d/cocos2d-iphone/commit/60f9cc98783b9a6a5635db4f468f83e0511c74c8

AwDogsGo2Heaven
  • 952
  • 11
  • 26