我要做的是运行一个包含的动作(playForwardAnimation) 多个操作(在不同节点上运行)并在完成所有操作后,运行名为playBackwardAnimation的操作。 这是代码:`
SKAction *wait = [SKAction waitForDuration:3.5];
SKAction *forwardAnimationAction = [SKAction animateWithTextures:forwardAnimationFrames timePerFrame:0.1];
SKAction *backwardAnimationAction = [SKAction animateWithTextures:backwardAnimationFrames timePerFrame:0.1];
SKAction *forwardAnimation = [SKAction sequence:@[wait , forwardAnimationAction, wait, forwardAnimationAction]];
SKAction *backwardAnimation = [SKAction sequence:@[wait , backwardAnimationAction, wait, forwardAnimationAction]];
SKAction *playForwardAnimation = [SKAction runBlock:^{
[node5 runAction:forwardAnimation completion:^{
[node4 runAction:[SKAction rotateByAngle:-0.1 duration:0.3]];
[node3 runAction: [SKAction rotateByAngle:-0.2 duration:0.3]];
[node2 runAction: [SKAction rotateByAngle:-0.3 duration:0.3]];
NSLog(@"forward action executed");
}];
}];
SKAction *playBackwardAnimation = [SKAction runBlock:^{
[node5 runAction:backwardAnimation completion:^{
[node4 runAction:[SKAction rotateByAngle:0.1 duration:0.3]];
[node3 runAction: [SKAction rotateByAngle:0.2 duration:0.3]];
[node2 runAction: [SKAction rotateByAngle:0.3 duration:0.3]];
NSLog(@"backward action executed");
}];
}];
SKAction *sequence = [SKAction sequence:@[playForwardAnimation,playBackwardAnimation]];
SKAction *action = [SKAction repeatActionForever:sequence];
[holder runAction:action];`
问题是playForwardAnimation完全结束后没有调用playBackwardAnimation。看起来两个动画同时被调用。怎么做到这一点?动画中使用的节点层次结构如下所示:
持有人(upperArea)
upperArea(node4,node3,node2)
节点4(节点5)
答案 0 :(得分:3)
不幸的是,当你在这样的不同节点上运行动作并且需要严格的序列时,它会变得混乱。这是实现目标的一种方法。我确定有很多。
希望我做对了
SKAction *wait = [SKAction waitForDuration:3.5];
SKAction *forwardAnimationAction = [SKAction animateWithTextures:forwardAnimationFrames timePerFrame:0.1];
SKAction *backwardAnimationAction = [SKAction animateWithTextures:backwardAnimationFrames timePerFrame:0.1];
SKAction *forwardAnimation = [SKAction sequence:@[wait , forwardAnimationAction, wait, forwardAnimationAction]];
SKAction *backwardAnimation = [SKAction sequence:@[wait , backwardAnimationAction, wait, forwardAnimationAction]];
CGFloat rotateDur = 0.3;
SKAction *rotateWait = [SKAction waitForDuration:rotateDur];
SKAction *forwardAnimationBlock = [SKAction runBlock:^{
[node4 runAction:[SKAction rotateByAngle:-0.1 duration:rotateDur]];
[node3 runAction: [SKAction rotateByAngle:-0.2 duration:rotateDur]];
[node2 runAction: [SKAction rotateByAngle:-0.3 duration:rotateDur]];
}];
SKAction *backwardAnimationBlock = [SKAction runBlock:^{
[node4 runAction:[SKAction rotateByAngle:-0.1 duration:rotateDur]];
[node3 runAction: [SKAction rotateByAngle:-0.2 duration:rotateDur]];
[node2 runAction: [SKAction rotateByAngle:-0.3 duration:rotateDur]];
}];
SKAction *sequence = [SKAction sequence:@[forwardAnimation, forwardAnimationBlock, rotateWait, backwardAnimation, backwardAnimationBlock, rotateWait]];