我想要让两个(或更多)
有没有办法在两个或多个精灵上运行持续时间相同的并行
以下是一个示例,说明了不起作用的原则:
我希望你能够理解我的英语和思路。
//Micke....
SKSpriteNode
同步移动。任何差异都会显示出来。我尝试按顺序触发每个精灵的SKAction
,当最后一个完成时触发一个新的移动。但事实证明,这些动作结束的顺序与它们开始的顺序不同,这会导致微小的时间差异,是可以察觉到的。有没有办法在两个或多个精灵上运行持续时间相同的并行
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];}];
}
我希望你能够理解我的英语和思路。
//Micke....