2012-03-03 3 views
1

애니메이션 화 된 하나의 탄환을 만들면 문제가 해결됩니다. 사용자가 초를 만들면 첫 번째 애니메이션이 멈 춥니 다.Cocos2D - 두 번째 스프라이트에 애니메이션을 적용하면 애니메이션이 멈 춥니 다.

좋아가 여기 내 초기화에서 그것을하고 있어요 방법 : 사용자가 화면을 탭 때 호출되는 내 생성 총알 방법에

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

CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode 
             batchNodeWithFile:@"acorns.png"]; 
[self addChild:spriteSheet]; 

NSMutableArray *flyingFrames = [NSMutableArray array]; 
    for(int i = 1; i <= 4; ++i) { 
     [flyingFrames addObject: 
     [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: 
      [NSString stringWithFormat:@"acorn%d.png", i]]]; 
    } 

CCAnimation *flying = [CCAnimation 
           animationWithFrames:flyingFrames delay:0.5f]; 

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

그럼, 수행

CCSprite *bullet = [CCSprite spriteWithSpriteFrameName:@"acorn1.png"]; 
bullet.position = CGPointMake(140.0f, FLOOR_HEIGHT+145.0f); 
[bullet runAction:_flying]; 

[self addChild:bullet z:9]; 
[bullets addObject:bullet]; 

처음으로 사용자가 탭하면 모든 것이 정상적으로 작동합니다. 두 번째로 애니메이션 글 머리 기호가 만들어 지지만 기존의 글 머리 기호 애니메이션은 중단됩니다.

답변

2

나는 각 스프 라이트가 자체 액션을 가져야한다고 믿는다. 즉, 액션이 진행되는 동안 액션을 재사용 할 수 없다. 당신은 재사용을 위해 배열을 유지의주의해야하므로 flyingFrames는 여러 애니메이션에서 참조 할 수있는

CCSprite *bullet = [CCSprite spriteWithSpriteFrameName:@"acorn1.png"]; 
bullet.position = CGPointMake(140.0f, FLOOR_HEIGHT+145.0f); 
id _fly=[CCAnimation animationWithFrames:flyingFrames delay:0.5f]; 
id _flyForever = [[CCRepeatForever _fly]; 
[bullet runAction:_flyForever]; 
[self addChild:bullet z:9]; 
[bullets addObject:buller]; 

:처럼 뭔가.