gpt4 book ai didi

swift - 使用 EnumerateChildNodeWithName 的序列操作

转载 作者:行者123 更新时间:2023-11-30 10:14:39 25 4
gpt4 key购买 nike

我想要两种不同类型的节点依次将 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.

关于swift - 使用 EnumerateChildNodeWithName 的序列操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30860833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com