按钮"按"我按如下方式执行动画:
//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和所有内容)
时才有效答案 0 :(得分:1)
据我所知,这个动作第一次创建CCAnimation对象并将其存储在CCAnimationCache中。尝试预先设置动画或在init方法中初始化动画,然后将其存储起来。在您的按钮上单击只是重新创建动作,而不是动画。