Sequence Action With EnumerateChildNodeWithName

91 views Asked by At

I want two different types of nodes to fade there alpha to 0 one after the other (with a sequence). However to find the nodes to fade, I'm using EnumerateChildNodeWithName and there is two of them, so I'm unable (I think) to use a sequence because I would have to use the sequence outside the EnumerateChildNodeWithName (because there is two of them) and at that point, I lose control of the nodes.

Not sure if this makes sense, but here is my code (this fades both types of nodes are the same time):

    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)
            }

        }
    }
1

There are 1 answers

3
Wraithseeker On BEST ANSWER

The solution to this would be to make use of SKAction Sequences, it only runs the second action once the first action is completed.

From the Apple Documentation

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.