在不同的节点上一个接一个地运行动作
Running actions one after another on different nodes
我想做的是运行一个动作(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。看起来两个动画都被同时调用了。如何做到这一点?动画中使用的节点层次结构如下所示:
holder (upperArea)
upperArea (node4,node3,node2)
节点 4(节点 5)
不幸的是,当您像这样在不同的节点上执行 运行 操作并且您需要严格的顺序时,它会变得混乱。这是一种方法。我敢肯定有很多。
希望我做对了
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]];
我想做的是运行一个动作(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。看起来两个动画都被同时调用了。如何做到这一点?动画中使用的节点层次结构如下所示:
holder (upperArea)
upperArea (node4,node3,node2)
节点 4(节点 5)
不幸的是,当您像这样在不同的节点上执行 运行 操作并且您需要严格的顺序时,它会变得混乱。这是一种方法。我敢肯定有很多。
希望我做对了
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]];