简体   繁体   English

如何在Spritekit中创建SKActions数组

[英]How to create an array of SKActions in Spritekit

I am trying to create an array of SKActions in Spritekit using objective-c so that two arrays execute in parallel. 我正在尝试使用Objective-C在Spritekit中创建SKActions数组,以便两个数组并行执行。 "rotation" is not an array which is fine with me, unless it is causing the issue which I doubt is the problem here. “旋转”不是一个适合我的数组,除非它引起了我怀疑这里是问题的问题。 What I am expecting from this code is that actionMove and rotation will run in parallel and then it moves on to actionMove1 and actionMove2 and finishes the runAction. 我从此代码中期望的是actionMove和rotation将并行运行,然后继续进行到actionMove1和actionMove2并完成runAction。 I am getting the following error in the last line of code shown below (added just the portion of the code needed). 我在下面显示的代码的最后一行中收到以下错误(仅添加了所需代码的一部分)。

Collection element of type 'SKAction *__strong [3]' is not an Objective-C object 类型为“ 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]]];

I believe what you want is a combination of group: and sequence: actions. 我相信您想要的是group:和sequence:动作的组合。 Groups will run together and sequence will wait until the previous action is finished. 组将一起运行,序列将等待直到上一个操作完成。

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

You might find this link helpful Adding Actions to Nodes It does a good job of show different groups and sequences. 您可能会发现此链接很有用。 将操作添加到节点它可以很好地显示不同的组和序列。

Hopefully that will give you the desired result. 希望能给您期望的结果。

Edit 编辑

If you are looking to run rotation while running move actions in oder it would look like this. 如果希望在运行移动动作时同时运行旋转,则看起来像这样。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM