0

我不明白,我绝对不能让它工作,我想要一个播放动画并使用CCAnimateansCCMoveTo类移动精灵的动作序列。这些类是否存在错误或特殊之处,导致在这样的 CCSequence 动作中将其串在一起时不会移动或动画。

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

4

2 回答 2

3

如果您希望移动和动画动作并行运行,您可以使用:

选项 1:使用 CCSpawn 而不是 CCSequence。需要 CCSequence 是因为您想在完成后调用一个函数。

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];

选项2:只需多次添加任何操作,并将并行运行。由于 func-call 再次需要 CCSequence:

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]];
于 2013-05-08T22:40:07.750 回答
1

这个序列的作用是:

  • 将自己移动到目的地
  • 到达目的地后,播放行走动画
  • 行走动画完成后,运行选择器

我敢打赌,您的意思是分别同时运行移动和动画动作(每个动作都有自己的 runAction 调用),而不是在一个序列中。

于 2013-05-08T21:18:16.657 回答