0

I don´t understand, I absolutely cannot get this to work, I want a sequence of actions that plays an animation and moves the sprite using the CCAnimate ans CCMoveTo classes. Is there a bug or something special about these classes, cause it will not move nor animate when stringing it together in a CCSequence of actions like this.

    action = [CCSequence actions:
                              [CCMoveTo actionWithDuration:moveDuration position:touchLocation],
                              [CCAnimate actionWithAnimation:self.walkingAnim],
                              [CCCallFunc actionWithTarget:self selector:@selector(objectMoveEnded)], nil];
 [self runAction:action];

I

Tom Lilletveit
  • 1,872
  • 3
  • 31
  • 57

2 Answers2

3

If you want the move and animate action to run paralel you can use:

Option1: use CCSpawn instead of a CCSequence. CCSequence is needed because you would like to call a function after completion.

id action = [CCSpawn actions:
                              [CCMoveTo actionWithDuration:moveDuration position:touchLocation],
                              [CCAnimate actionWithAnimation:self.walkingAnim], 
                               nil];

id seq = [CCSequence actions:
                              action,
                              [CCCallFunc actionWithTarget:self selector:@selector(objectMoveEnded)], 
                               nil];

[self runAction:seq];

Option2: just add any action multiple times and will be run in paralel. Because of the func-call a CCSequence again needed:

id action = [CCSequence actions:
                              [CCMoveTo actionWithDuration:moveDuration position:touchLocation],
                              [CCCallFunc actionWithTarget:self selector:@selector(objectMoveEnded)], 
                               nil];
[self runAction:action];
[self runAction:[CCAnimate actionWithAnimation:self.walkingAnim]];
nzs
  • 3,252
  • 17
  • 22
1

What this sequence does is:

  • move self to the destination
  • once arrived at destination, play the walking animation
  • when the walk animation is finished, run the selector

I bet you meant to run the move and animate actions separately and at the same time (each with their own call to runAction) and not within a sequence.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217