我想同步移动两个(或更多)SKSpriteNode
。任何差异都会显示出来。我尝试按顺序为每个 Sprite 触发 SKAction
,当最后一个 Sprite 完成时,它会触发一个新 Action 。但事实证明,操作的结束顺序与它们开始的顺序不同,这会导致明显的时间差异。
有没有办法在两个或多个具有持续时间的 Sprite 上并行运行 SKActions
,以便它们在完全相同的时间结束,或者至少按照它们开始的顺序?
这是一个不起作用的原理示例:
- (void)testMethod1{
SKSpriteNode *child_1=[arrayWithSprites objectAtIndex:1];
SKSpriteNode *child_2=[arrayWithSprites objectAtIndex:2];
//This doesn't work.
[child_1 runAction:[SKAction moveToX:20.0 duration:0.5]];
[child_2 runAction:[SKAction moveToX:20.0 duration:0.5]
completion:^{[self testMethod1];}];
//Actions might not be finished in the order they are started.
}
这是一种我还没有尝试过但想知道它是否可以解决我的问题的方法:
- (void)testMethod2{
SKSpriteNode *child_1=[arrayWithSprites objectAtIndex:1];
SKSpriteNode *child_2=[arrayWithSprites objectAtIndex:2];
//Will this guarantee total syncronisation?
[self runAction:[SKAction group:[NSArray arrayWithObjects:
[SKAction runBlock:^{[child_1 runAction:[SKAction moveToX:20.0 duration:0.5]];}],
[SKAction runBlock:^{[child_2 runAction:[SKAction moveToX:20.0 duration:0.5]];}],
nil]]
completion:^{[self testMethod2];}];
}
我希望我的英语和想法是可以理解的。
//米克....
最佳答案
只需添加一个容器SKNode
,然后它们就会同时移动:
SKNode *containerNode = [[SKNode alloc] init];
[containerNode addChild:node1];
[containerNode addChild:node2]; //add as many as necessary
[containerNode runAction:someAction]; //declare the action you want them both to perform
关于ios - 在两个或多个 SKSpriteNode 上同步 SKActions?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20935817/