带完成块的动作动画(Plist)

时间:2016-10-08 09:45:12

标签: objective-c sprite-kit skaction

无法在完成时播放动画

触摸,快乐动画应播放 - 当动画完成时,它应该返回空闲动画 (但是在快乐动画完成后没有任何反应)

  if ([touchedNode.name isEqualToString:@"myMonster"]) {

        id callHappy= [SKAction performSelector:@selector (playHappy) onTarget:self];
        id callIdle = [SKAction performSelector:@selector (ReturnToIdleAnimation) onTarget:self];
        NSArray *actionsequence = @[callHappy,callIdle];
        SKAction *allActions= [SKAction sequence:actionsequence];

        [myMonster runAction:allActions completion:^{
        NSLog(@"myMonster Action Complete");
       // [self ReturnToIdleAnimation];

        //*** [self PlayIdleAnimation];*** works
        // but am interested as to why is doesn't get called on the main game layer???


        }];
    }
}

-(void)ReturnToIdleAnimation
{
    [myMonster removeAllActions];
     NSLog(@"ReturnToIdleAnimation");
     [myMonster PlayIdleAnimation];
}

-(void)playHappy
{
     NSLog(@"playHappyAnimation");
     [myMonster PlayHappyAnimation];
}

///

logs  PlayHappyAnimation
      animation with completion finished

//在monsterClass.m中

    -(void)PlayAnimationNamed:(NSString*)string looping:(BOOL)isLooping
{
    //remove actions on sprite
    [self removeAllActions];

    //check if looping
    if (isLooping==YES) {
        self->animationAction = [self animationFromPlist:string];
        id repeat = [SKAction repeatActionForever:animationAction];
        [self runAction:repeat];
    }

     else if (isLooping==NO)
    {
      self->animationAction = [self animationFromPlist:string];
      SKAction* actionOnce = [SKAction sequence:@[animationAction]];

      [self runAction:actionOnce completion:^ {
      //when finished return to idle loop here
      NSLog(@"animation with completion finished");
      }];
     }
}

-(void)PlayIdleAnimation
{
    [self    PlayAnimationNamed:@"Monster_IdleAnimation_plist"looping:YES];
    NSLog(@"PlayIdleAnimation");
}
-(void)PlayHappyAnimation
{
    [self PlayAnimationNamed:@"Monster_Happy_Animation_plist"looping:NO];
     NSLog(@"PlayHappyAnimation");
}

0 个答案:

没有答案