在“按下”按钮上,我执行如下动画:
//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和所有东西)时,这才有效。
发布于 2012-10-10 13:35:42
据我所知,该操作第一次创建CCAnimation对象并将其存储在CCAnimationCache中。尝试预先执行动画,或在init方法中初始化动画,然后将其存储。然后在你的按钮上点击重新创建动作,而不是动画。
https://stackoverflow.com/questions/12820498
复制相似问题