如何在Spritekit中创建一个SKActions数组

时间:2015-03-10 02:14:32

标签: ios arrays sprite-kit skaction

我正在尝试使用objective-c在Spritekit中创建一个SKActions数组,以便两个数组并行执行。 "旋转"不是一个对我来说没问题的数组,除非它引起我怀疑这个问题的问题。我期望从这段代码中获得的是actionMove和rotation将并行运行,然后继续运行到actionMove1和actionMove2并完成runAction。我在下面显示的最后一行代码中收到以下错误(仅添加了所需代码部分)。

类型的集合元素' SKAction * __ strong [3]'不是Objective-C对象

SKAction * actionMove = [SKAction moveTo:CGPointMake(actualX2, actualY2) duration:actualDuration];
SKAction * actionMove1 = [SKAction moveTo:CGPointMake(actualX3, actualY3) duration:actualDuration];
SKAction * actionMove2 = [SKAction moveTo:CGPointMake(actualX4, actualY4) duration:actualDuration];
int rotate = arc4random() % 5;
SKAction * rotation = [SKAction rotateByAngle:M_PI/rotate duration:0.5];

SKAction * moveArray[] = {actionMove, actionMove1, actionMove2};

[game_piece1 runAction:[SKAction group:@[moveArray, rotation]]];

1 个答案:

答案 0 :(得分:1)

我相信你想要的是group:和sequence:actions的组合。组将一起运行,序列将一直等到上一个操作完成。

SKAction * actionMove = [SKAction moveTo:CGPointMake(actualX2, actualY2) duration:actualDuration];
SKAction * actionMove1 = [SKAction moveTo:CGPointMake(actualX3, actualY3) duration:actualDuration];
SKAction * actionMove2 = [SKAction moveTo:CGPointMake(actualX4, actualY4) duration:actualDuration];
int rotate = arc4random() % 5;
SKAction * rotation = [SKAction rotateByAngle:M_PI/rotate duration:0.5];

SKAction *firstStep = [SKAction group:@[actionMove, rotation]];
SKAction *sequence = [SKAction sequence:@[firstStep, actionMove1, actionMove2]];

[game_piece1 runAction:sequence];

您可能会发现此链接很有用Adding Actions to Nodes它可以很好地展示不同的群组和序列。

希望这会给你想要的结果。

修改

如果你想在oder中运行move动作时运行旋转,它将会是这样的。

SKAction * actionMove = [SKAction moveTo:CGPointMake(actualX2, actualY2) duration:actualDuration];
SKAction * actionMove1 = [SKAction moveTo:CGPointMake(actualX3, actualY3) duration:actualDuration];
SKAction * actionMove2 = [SKAction moveTo:CGPointMake(actualX4, actualY4) duration:actualDuration];
int rotate = arc4random() % 5;
SKAction * rotation = [SKAction rotateByAngle:M_PI/rotate duration:0.5];

SKAction *sequence = [SKAction sequence:@[actionMove, actionMove1, actionMove2]];
SKAction *group = [SKAction group:@[sequence, rotation]];

[game_piece1 runAction:group];