使用不同的节点运行 SKActions 序列 [英] Run SKActions sequence with different nodes
本文介绍了使用不同的节点运行 SKActions 序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以创建一个 SKAction.sequence,它会一个一个地运行一个节点的动作.但是,如果我想用不同的节点做一个序列,我该怎么做.我想做这样的事情:
I know that I can create an SKAction.sequence which will run the actions of one node one by one. But how can I do that if I want to do a sequence with different nodes. I'd like to do something like that:
- 从节点 A 运行操作
- 等待 2 秒
- 从节点 B 运行操作.
推荐答案
如果两个节点都是唯一命名的并且是同一个节点的子节点,可以使用runAction:onChildWithName:
,如下:
If both nodes are uniquely named and are children of the same node, you can use runAction:onChildWithName:
, as follows:
SKAction *action = [SKAction sequence:
@[[SKAction runAction:[SKAction moveTo:CGPointMake(200.0f, 200.0f) duration:1.0f]
onChildWithName:@"NODEA"],
[SKAction waitForDuration:2.0f],
[SKAction runAction:[SKAction moveTo:CGPointMake(200.0f, 200.0f) duration:1.0f]
onChildWithName:@"NODEB"]]];
[parent runAction:action];
更一般地,您可以使用 runBlock:
作为 SKAction 序列中的一个步骤来执行几乎所有操作:
More generally, you can use runBlock:
to do pretty much anything as a step in an SKAction sequence:
SKAction *action = [SKAction sequence:
@[[SKAction runBlock:^{
[nodeA runAction:[SKAction moveTo:CGPointMake(200.0f, 200.0f) duration:1.0f]];
}],
[SKAction waitForDuration:2.0f],
[SKAction runBlock:^{
[nodeB runAction:[SKAction moveTo:CGPointMake(200.0f, 200.0f) duration:1.0f]];
}]]];
[parent runAction:action];
这篇关于使用不同的节点运行 SKActions 序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文