使用 EnumerateChildNodeWithName 的序列操作
Sequence Action With EnumerateChildNodeWithName
我想要两种不同类型的节点一个接一个地从 alpha 淡化到 0(有一个序列)。但是,为了找到要淡入淡出的节点,我正在使用 EnumerateChildNodeWithName 并且其中有两个,所以我无法(我认为)使用序列,因为我必须使用 EnumerateChildNodeWithName 之外的序列(因为有两个他们),那时,我失去了对节点的控制。
不确定这是否有意义,但这是我的代码(这会同时淡化两种类型的节点):
nodeMovingPlatform1.enumerateChildNodesWithName("*") {
node, stop in
if node.position.x + nodeMovingPlatform1.position.x > self.frame.size.width/2 + node.frame.size.width/2 {
node.removeFromParent()
} else {
if node.name == "landscapeTrigger" {
node.name = "landscape"
node.runAction(actionFadeAlphaTo0_3)
}
}
}
nodeMovingPlatform2.enumerateChildNodesWithName("*") {
node, stop in
if node.position.x + nodeMovingPlatform2.position.x > self.frame.size.width/2 + node.frame.size.width/2 {
node.removeFromParent()
} else {
if node.name == "landscapeTrigger" {
node.name = "landscape"
node.runAction(actionFadeAlphaTo0_3)
}
}
}
这个问题的解决方案是使用 SKAction Sequences
,它只会在第一个动作完成后运行第二个动作。
来自 Apple 文档
A sequence is a set of actions that run consecutively. When a node
runs a sequence, the actions are triggered in consecutive order. When
one action completes, the next action starts immediately. When the
last action in the sequence completes, the sequence action also
completes.
我想要两种不同类型的节点一个接一个地从 alpha 淡化到 0(有一个序列)。但是,为了找到要淡入淡出的节点,我正在使用 EnumerateChildNodeWithName 并且其中有两个,所以我无法(我认为)使用序列,因为我必须使用 EnumerateChildNodeWithName 之外的序列(因为有两个他们),那时,我失去了对节点的控制。
不确定这是否有意义,但这是我的代码(这会同时淡化两种类型的节点):
nodeMovingPlatform1.enumerateChildNodesWithName("*") {
node, stop in
if node.position.x + nodeMovingPlatform1.position.x > self.frame.size.width/2 + node.frame.size.width/2 {
node.removeFromParent()
} else {
if node.name == "landscapeTrigger" {
node.name = "landscape"
node.runAction(actionFadeAlphaTo0_3)
}
}
}
nodeMovingPlatform2.enumerateChildNodesWithName("*") {
node, stop in
if node.position.x + nodeMovingPlatform2.position.x > self.frame.size.width/2 + node.frame.size.width/2 {
node.removeFromParent()
} else {
if node.name == "landscapeTrigger" {
node.name = "landscape"
node.runAction(actionFadeAlphaTo0_3)
}
}
}
这个问题的解决方案是使用 SKAction Sequences
,它只会在第一个动作完成后运行第二个动作。
来自 Apple 文档
A sequence is a set of actions that run consecutively. When a node runs a sequence, the actions are triggered in consecutive order. When one action completes, the next action starts immediately. When the last action in the sequence completes, the sequence action also completes.