Multiple child nodes in EnumerateChildNodesWithName

I am removing and adding nodes using enumerateChildNodesWithName. I am wondering if there is a way to use enumerateChildNodesWithName with multiple names. For example, at the moment I am using the following:

    nodeBase.enumerateChildNodesWithName("ground", usingBlock: {
        node, stop in
        if node.position.x + positionX < -self.frame.size.width/2 - sizeSegmentWidth/2 {
            node.removeFromParent()
        }
    })

    nodeBase.enumerateChildNodesWithName("obstacle", usingBlock: {
        node, stop in
        if node.position.x + positionX < -self.frame.size.width/2 - sizeSegmentWidth/2 {
            node.removeFromParent()
        }
    })

      

But what I am hoping to do is something like this (it doesn't work, just an example of what I am trying to do):

    nodeBase.enumerateChildNodesWithName("ground" || "obstacle", usingBlock: {
        node, stop in
        if node.position.x + positionX < -self.frame.size.width/2 - sizeSegmentWidth/2 {
            node.removeFromParent()
        }
    })

      

+3


source to share


1 answer


You can do:

enumerateChildNodesWithName("*") { node, _ in
    if node.name == "ground" || node.name == "obstacle" {
        // ...
    }
}

      



"*"

means you list all the nodes that are children of the scene (assuming it is the scene that is calling enumerateChildNodesWithName

). If you want to check all nodes , use instead "//*"

.

+5


source







All Articles