CCAnimate 仅在第一次滞后



在按钮"按下"上,我执行一个动画,如下所示:

//create sprite
animatedSprite = [[CCSprite alloc] initWithFile:@"transparentPixel.png" rect:CGRectMake(0, 0, 218, 218)];
SET_POS(animatedSprite, 167, 51);
[self addChild:animatedSprite z:5000];
//animate sprite            
[animatedSprite runAction:[CCAnimate actionWithAnimation:[[CCAnimationCache sharedAnimationCache] animationByName:@"skill1use"]]];
//run cleanup fnktion
[animatedSprite performSelector:@selector(removeFromParentAndCleanup:) withObject:[NSNumber numberWithBool:YES] afterDelay:3];            
[animatedSprite release];

以前我加载了帧:

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:[CCDirector sharedDirector].contentScaleFactor>1?@"skill_01_ani@2x.plist":@"skill_01_ani.plist"];
[[CCAnimationCache sharedAnimationCache] addAnimation:[CCAnimation animationWithSpriteSequence:[CCDirector sharedDirector].contentScaleFactor>1?@"skill_01_ani%04d@2x.png":@"skill_01_ani%04d.png" numFrames:34 delay:1/24.0] name:@"skill1use"];
但是,动画在第一次

之后运行得更流畅,第一次需要一段时间才能开始。我预加载动画有误吗?有没有办法让动画第一次也能顺利运行?

更新

如果我在预览中设置以下内容,它第一次运行速度很快:

CCSprite *animatedSprite = [[CCSprite alloc] initWithFile:@"transparentPixel.png" rect:CGRectMake(0, 0, 218, 218)];
[self addChild:animatedSprite z:5000];
[animatedSprite runAction:[CCAnimate actionWithAnimation:[[CCAnimationCache sharedAnimationCache] animationByName:@"skill1use"]]];
[animatedSprite performSelector:@selector(removeFromParentAndCleanup:) withObject:[NSNumber numberWithBool:YES] afterDelay:3];
[animatedSprite release];

因为它与运行动画相同。但是,这仅在我实际显示动画(带有addChild和所有内容)时才有效

据我所知,此操作第一次创建 CCAnimation 对象并将其存储在 CCAnimationCache 中。尝试预缓存动画或在 init 方法中初始化它,然后存储它。在您的按钮上单击只是重新创建动作,而不是动画。

最新更新