Permalink
Browse files

Tested bug from forum topic.. http://www.cocos2d-iphone.org/forum/top…

…ic/30756

found two culprits, 

-when adding animation frames with addFrames:, the delay per unit needs to be set first, else the duration is 0. Added a assert to make sure of this. 

-the update method of the animation action couldn't display more than one frame per 'tick'. In cases of low FPS or a delayPerUnit that is < 1/FPS more frames per 'tick' need to be displayed.
  • Loading branch information...
araker committed Sep 14, 2012
1 parent b177138 commit 60f9cc98783b9a6a5635db4f468f83e0511c74c8
Showing with 8 additions and 4 deletions.
  1. +3 −3 cocos2d/CCActionInterval.m
  2. +1 −0 cocos2d/CCAnimation.m
  3. +4 −1 tests/ActionsTest.m
@@ -1368,9 +1368,9 @@ -(void) update: (ccTime) t
[[NSNotificationCenter defaultCenter] postNotificationName:CCAnimationFrameDisplayedNotification object:target_ userInfo:dict];
nextFrame_ = i+1;
-
- break;
- }
+
+ }//could be more than one frame per tick, due to low frame rate or frame delta < 1/FPS
+ else break;
}
}
View
@@ -161,6 +161,7 @@ -(void) addFrame:(CCSpriteFrame*)frame
[frames_ addObject:animFrame];
[animFrame release];
+ NSAssert(delayPerUnit_ != 0, @"set a delayPerUnit before adding frames");
// update duration
duration_ += delayPerUnit_;
totalDelayUnits_++;
View
@@ -537,6 +537,7 @@ -(void) onEnter
// Left: using manual animation.
CCAnimation* animation = [CCAnimation animation];
+ [animation setDelayPerUnit:0.016666f];
for( int i=1;i<15;i++)
[animation addFrameWithFilename: [NSString stringWithFormat:@"grossini_dance_%02d.png", i]];
@@ -550,7 +551,9 @@ -(void) onEnter
CCAnimation *animation2 = [cache animationByName:@"dance_1"];
id action2 = [CCAnimate actionWithAnimation:animation2];
- [tamara runAction: [CCSequence actions: action2, [action2 reverse], nil]];
+ [animation setDelayPerUnit:0.0166666f];
+
+ [tamara runAction: [CCSequence actions: action2, [action2 reverse], nil]];
observer_ = [[NSNotificationCenter defaultCenter] addObserverForName:CCAnimationFrameDisplayedNotification object:nil queue:nil usingBlock:^(NSNotification* notification) {

1 comment on commit 60f9cc9

@ricardoquesada

This comment has been minimized.

Show comment Hide comment
@ricardoquesada

ricardoquesada Nov 12, 2012

Contributor

Applied in v2.x as well.

Contributor

ricardoquesada commented on 60f9cc9 Nov 12, 2012

Applied in v2.x as well.

Please sign in to comment.