2012-10-10 47 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