2012-01-30 3 views
1

제발 도와주세요. 여러 개의 CCSpriteBatchNode 객체를로드하고 좌표를 변경하고 프레임을 회전하여 움직이는 것처럼 보이게하는 게임을 만들고 있습니다. 하나의 좌표에서 다른 좌표로 하나의 CCSpriteBatchNode 객체를 움직이는 것을 이미 달성했으며 애니메이션이 적용되었습니다. 이제 또 다른 매우 다른 애니메이션을 작성하고 다른 스프라이트 시트 파일을로드하고 다른 곳으로 이동해야합니다. 어떻게해야합니까?cocos2D에 여러 스프라이트 시트를 추가하고 스프라이트 하나처럼 보이게 만드는 방법은 무엇입니까?

이 내 코드는 지금까지 있습니다 :

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"PotkaEntry.plist"]; 

CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"PotkaEntry.pvr.ccz"]; 

[self addChild:spriteSheet]; 

NSMutableArray *entryAnimFrames = [NSMutableArray array]; 

for(int i = 1; i<=12; i++) 
{ 
    [entryAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Potka_entry%d.png", i]]]; 
} 

CCAnimationCache *entryAnim = [CCAnimation animationWithFrames:entryAnimFrames delay:0.08f]; 

CGSize winSize = [CCDirector sharedDirector].winSize; 

self->_body1 = [CCSprite spriteWithSpriteFrameName:@"Potka_entry1.png"]; 

_body1.position = CGPointMake(winSize.width/2, 0); 

self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:entryAnim restoreOriginalFrame:NO]]; 

[_body1 runAction:_walkAction]; 

_body1.scale = 0.4; 

[spriteSheet addChild:_body1]; 

id entryAction = [CCMoveTo actionWithDuration:5.0f position:ccp(winSize.width/2,60)]; 

[_body1 runAction:entryAction]; 
+0

다른 CCSpriteBatchNode를 만들지 않는 이유는 무엇입니까? 어떤 문제가 있습니까? – FBryant87

+0

동일한 CCSpriteBatchNode 객체와 다른 스프라이트 프레임 (.plist 파일)에 동일한 스프라이트 시트 (다른 ​​.pvr.ccz 파일 에서처럼)를 동일한 CCSpriteFrameCache 객체에로드하는 방법을 묻습니다. 내가 그렇게한다면, 다른 CCFLriteBatchNode 객체를로드하기 전에 제거해야합니까? 미리 감사드립니다. – Shahnawaz

답변

5

당신은 각 당신이

(spritesheet 나는 결합 pvr.ccz 파일과 .plist 파일을 의미로)를 사용 spritesheet에 대한 새로운 CCSpriteBatchNode을 작성해야 CCSpriteFrameCache는 모든 장면과 클래스에서 공유되는 단일 캐시입니다. 이 메서드를 호출 할 때 :

[CCSpriteFrameCache sharedSpriteFrameCache] 

매번 새로운 CCSpriteFrameCache 개체를 만들지는 않으며 하나의 인스턴스 만 있습니다. 로드 된 모든 스프라이트 시트를이 단일 캐시에 저장합니다. 그래서 당신과 같이 캐시로 2 spritesheets를로드 할 수 :

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"sheet1.plist"]; 
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"sheet2.plist"]; 

를 그런 다음, 당신이 배치 노드에서 하나 개 이상의 시트를 가질 수 없습니다 각 spritesheet에 대한 CCSpriteBatchNode을 만들어야합니다

CCSpriteBatchNode *spriteSheet1 = [CCSpriteBatchNode batchNodeWithFile:@"sheet1.pvr.ccz"]; 
CCSpriteBatchNode *spriteSheet2 = [CCSpriteBatchNode batchNodeWithFile:@"sheet2.pvr.ccz"]; 

당신 그런 다음 원하는 경우이 배치 노드를 모두 레이어에 추가 할 수 있습니다. 배치 노드에 추가 된 스프라이트는 배치 노드가 사용중인 스프라이트 시트에 있어야합니다.

+0

이 개념을 지워 줘서 고마워. 시간이 있다면 나는 한 가지 더 질문해야한다. 나는 이것을 구현하는 데 어려움을 겪고있다. spriteSheet1이 (10,10)으로 올라가 사라져서 spriteSheet2로 바뀌면이 코드를 사용하면 전체 스프라이트가 처음부터 모두 사라지고 전혀 나타나지 않는다고 가정 해 봅시다 : '[spriteSheet1 removeFromParentAndCleanup : 예]; – Shahnawaz

관련 문제