Playing sequence of PNG files in cocos2d iphone
I want 开发者_Python百科to play an sequence of png files for animation. I tried executing the following code in cocos2d iphone
(void) onEnter {
[super onEnter];
roadSprite=[[Sprite spriteWithFile:@"R00.png"] retain];
[roadSprite setPosition:ccp(240,160)];
[self addChild:roadSprite z:5];
Animation* animation = [Animation animationWithName:@"animation" delay:0];
for( int i=0;i<25;i++)
{
[animation addFrameWithFilename: [NSString stringWithFormat:@"R%02d.png", i]];
}
id action1 = [Animate actionWithAnimation: animation];
[roadSprite runAction:action1];
}
The animation doesnt get played instead the R00.png gets displayed lastly. Can anyone help me to find the mistake.
I don't see much of anything going wrong there, except perhaps in the setting of the delay.
You're setting delay to 0. Delay doesn't mean "how long should I wait before playing this animation" but it means "how much time must I wait before displaying each picture". Setting that to 0 would mean it doesn't wait at all, and your animation is finished! Tada!
Set your delay to the amount of time between each frame. In normal animation, this is 1.0f/24.0f (or 0.04, rounded off)
精彩评论