2012-10-10 44 views
0

按键“按”我如下执行动画:CCAnimate laggy仅在第一次

//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>[email protected]"[email protected]":@"skill_01_ani.plist"]; 
[[CCAnimationCache sharedAnimationCache] addAnimation:[CCAnimation animationWithSpriteSequence:[CCDirector sharedDirector].contentScaleFactor>[email protected]"skill_01_ani%[email protected]":@"skill_01_ani%04d.png" numFrames:34 delay:1/24.0] name:@"skill1use"]; 

然而,动画运行后顺利得多第一次,它第一次需要一段时间,直到它开始。我是否预载了动画?有没有办法让动画第一次顺利运行?

UPDATE

如果我设置下面的运行速度很快第一次预览:

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和所有内容)

+1

我对使用contentScaleFactor确定@ 2x文件加载感到畏惧。你为什么不使用cocos2d的native -hd文件扩展名? – LearnCocos2D

+0

它比重命名所有文件更容易;) – Daniel

+0

不认为它真的更容易。收拾您的所有文件与zwoptex或texturepacker如果我预装你将有只有在所有的艺术 – Morion

回答

1

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

+0

几个地图集'[CCAnimate actionWithSpriteSequence:[CCDirector sharedDirector] .contentScaleFactor> 1 @“skill_01_ani%[email protected]”:@ “skill_01_ani%04d.png”numFrames:34 delay:1/24.0 restoreOriginalFrame:NO]'我仍然有同样的问题。 – Daniel

+0

尝试在init方法中创建CCAnimation对象并将其添加到CCAnimationCache。然后创建CCAnimate与actionWithAnimation:restoreOriginalFrame构造 – Morion

+0

我已经更新的代码(见问题)..还是一样的结果:( – Daniel