首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CCAnimate滞后是第一次

CCAnimate滞后是第一次
EN

Stack Overflow用户
提问于 2012-10-10 13:27:15
回答 1查看 256关注 0票数 0

在“按下”按钮上,我执行如下动画:

代码语言:javascript
复制
//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];

在此之前,我用以下内容加载了框架:

代码语言:javascript
复制
[[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"];

然而,动画运行后,第一次平稳,第一次需要一段时间,直到它开始。我预装动画有问题吗?有没有办法让动画在第一次顺利运行?

更新

如果我在预览中设置了以下内容,则它在第一次运行时运行得很快:

代码语言:javascript
复制
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和所有东西)时,这才有效。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-10 13:35:42

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12820498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档