2012-10-10 1 views
0

버튼에 "언론은"나는 애니메이션을 실행 CCAnimate 랙이 처음에만

//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

@ 2x 파일로드를 결정하는 contentScaleFactor를 사용할 때 나는 움찔합니다. 왜 cocos2d의 네이티브 -hd 파일 확장자를 사용하지 않으시겠습니까? – LearnCocos2D

+0

내가 가진 모든 파일의 이름을 바꾸는 것보다 쉽습니다;) – Daniel

+0

정말 쉽지 않다고 생각하지 마십시오. 모든 파일을 zwoptex 또는 texturepacker로 압축하면 모든 아트에 대해 몇 개의 아틀라스 만 사용하게됩니다. – Morion

답변

1

처음으로이 액션은 CCAnimation 객체를 만들어 CCAnimationCache에 저장합니다. 애니메이션을 미리 캐시하거나 초기화 메소드에서 초기화 한 다음 저장하십시오. 그리고 버튼을 클릭하면 애니메이션이 아닌 액션을 다시 생성 할 수 있습니다.

+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

CCAnimation 객체를 생성하여 초기화 메소드의 CCAnimationCache에 추가하십시오. 그런 다음 actionWithAnimation : restoreOriginalFrame 생성자를 사용하여 CCAnimate를 만듭니다. – Morion

+0

코드를 업데이트했습니다. (질문 참조) .. 여전히 동일한 결과입니다. ( – Daniel