2014-06-16 3 views
0

여러 애니메이션적인 Cocos2D 3.0 나는 그의 프레임 3.Player 중지하고 작업이 수행 이동합니다 끝나면 그 실행을 시작 1.Player 화면 로딩 2.Then에 서서 여러 애니메이션을 실행하는 데 노력했다

문제 행동이 갈 것입니다 실행 작업 전에 실행 중 하나가 0.6 초 후 자신이 조치를 실행을 중지 플레이어 실행 등이 작업을 수행하고 작업을 실행 가서 4 초 후에는

- (void)didLoadFromCCB 
{ 
    CGSize winSize = [[CCDirector sharedDirector] viewSize]; 

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

    NSMutableArray *runAnimFrames = [NSMutableArray array]; 
    for(int i = 0; i <= 12; i++) 
    { 
     [runAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"cc_player/cc_player_run_pistol_%d.png", i]]]; 
    } 

    NSMutableArray *goAnimFrames = [NSMutableArray array]; 
    for(int i = 0; i <= 11; i++) 
    { 
     [goAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"cc_player/cc_player_go_%d.png", i]]]; 
    } 

    CCSprite *playerSprite = [CCSprite spriteWithImageNamed:@"cc_player/cc_player_idle_0.png"]; 

    playerSprite.scale = 1.3; 
    playerSprite.position = CGPointMake(100, (winSize.height/2) - 60); 
    [self addChild:playerSprite z:3]; 

    CCActionMoveTo *moveTo = [CCActionMoveTo actionWithDuration:8 position:CGPointMake(winSize.width+100/2, playerSprite.position.y)]; 


    CCAnimation *runAnim = [CCAnimation animationWithSpriteFrames:runAnimFrames delay:0.06]; 

    CCAnimation *goAnim = [CCAnimation animationWithSpriteFrames:goAnimFrames delay:0.06]; 

    CCActionAnimate *runAnimationAction = [CCActionAnimate actionWithAnimation:runAnim]; 

    CCActionAnimate *goAnimationAction = [CCActionAnimate actionWithAnimation:goAnim]; 




    CCActionCallBlock *next=[CCActionCallBlock actionWithBlock:^ 
    { 
     playerSprite.position = CGPointMake(playerSprite.position.x - 8, playerSprite.position.y + 6); 
     id goAction = [CCActionRepeat actionWithAction:goAnimationAction times:1]; 

     CCActionCallBlock *nextStep=[CCActionCallBlock actionWithBlock:^ 
     { 
      NSLog(@"***********not done"); 
      // [playerSprite stopAllActions]; 

     }]; 

     CCActionSpawn *groupAction1 = [CCActionSpawn actionWithArray:@[goAction,nextStep]]; 

     CCActionSequence *sequence2 = [CCActionSequence actionWithArray:@[groupAction1]]; 

     // [playerSprite stopAllActions]; 
     //CCActionSequence *goSequence = [CCActionSequence actions:moveTo,repeatingAnimation, nil]; 
     [playerSprite runAction:sequence2]; 

    }]; 


    CCActionSpawn *groupAction = [CCActionSpawn actionWithArray:@[moveTo, next]]; 

    CCActionSequence *sequence = [CCActionSequence actionWithArray:@[groupAction]]; 

    [playerSprite runAction:sequence]; 


    [playerSprite runAction:[CCActionRepeatForever actionWithAction:runAnimationAction]]; 
} 
+0

당신이 spritebuilder의 타임 라인으로이 애니메이션을 생성하지 않는 어떤 이유를 작업? – LearnCocos2D

+0

이제 코드가 잠시 후에 공유됩니다. 나중에 실행 애니메이션을 재사용하거나 애니메이션을 독립적으로 사용할 수 있기 때문에이 방법을 사용했습니다. – Ame

+0

죄송합니다. 8 시간의 대기 시간 후에 내 평판 se 8을 할 수 있기 때문에 지금 게시 할 수 있습니다. – Ame

답변

0

것은 내가 제거한 opticity 라인을 중지하는 데 도움이 수

완료 코드 애니메이션에서 시작 showi NG는 지금은 내 애니메이션의 변경 sequance을하고 지금은 좋은

(void)didLoadFromCCB 
{ 
CGSize winSize = [[CCDirector sharedDirector] viewSize]; 

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

NSMutableArray *runAnimFrames = [NSMutableArray array]; 
for(int i = 0; i <= 12; i++) 
{ 
    [runAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"cc_player/cc_player_run_pistol_%d.png", i]]]; 
} 

NSMutableArray *goAnimFrames = [NSMutableArray array]; 
for(int i = 0; i <= 11; i++) 
{ 
    [goAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"cc_player/cc_player_go_%d.png", i]]]; 
} 

CCSprite *playerSprite = [CCSprite spriteWithImageNamed:@"cc_player/cc_player_idle_0.png"]; 

playerSprite.scale = 1.3; 
playerSprite.position = CGPointMake(100, (winSize.height/2) - 60); 
[self addChild:playerSprite z:3]; 

CCActionMoveTo *moveTo = [CCActionMoveTo actionWithDuration:3 position:CGPointMake(300, playerSprite.position.y)]; 


CCAnimation *runAnim = [CCAnimation animationWithSpriteFrames:runAnimFrames delay:0.06]; 

CCAnimation *goAnim = [CCAnimation animationWithSpriteFrames:goAnimFrames delay:0.06]; 

CCActionAnimate *runAnimationAction = [CCActionAnimate actionWithAnimation:runAnim]; 

CCActionAnimate *goAnimationAction = [CCActionAnimate actionWithAnimation:goAnim]; 




CCActionCallBlock *next=[CCActionCallBlock actionWithBlock:^ 
{ 
    playerSprite.position = CGPointMake(playerSprite.position.x - 8, playerSprite.position.y + 6); 
    id goAction = [CCActionRepeat actionWithAction:goAnimationAction times:1]; 

    CCActionCallBlock *nextStep=[CCActionCallBlock actionWithBlock:^ 
    { 

     // [playerSprite stopAllActions]; 

    }]; 

    CCActionSpawn *groupAction1 = [CCActionSpawn actionWithArray:@[goAction,nextStep]]; 

    CCActionSequence *sequence2 = [CCActionSequence actionWithArray:@[groupAction1]]; 

    // [playerSprite stopAllActions]; 
    //CCActionSequence *goSequence = [CCActionSequence actions:moveTo,repeatingAnimation, nil]; 
    [playerSprite runAction:sequence2]; 

}]; 

[playerSprite runAction:[CCActionRepeatForever actionWithAction:runAnimationAction]]; 

CCActionSpawn *groupAction = [CCActionSpawn actionWithArray:@[moveTo,runAnimationAction]]; 

CCActionSequence *sequence = [CCActionSequence actionWithArray:@[groupAction,next]]; 

[playerSprite runAction:sequence]; 
}