Reputation: 1049
I'm removing and adding nodes using enumerateChildNodesWithName. I wondering if there is a way of using the enumerateChildNodesWithName with multiple names. For example, at the moment I am using the below:
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'm hoping to do is something like this (this doesn't work, just an example of what I'm 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()
}
})
Upvotes: 4
Views: 2091
Reputation: 22959
You could do:
enumerateChildNodesWithName("*") { node, _ in
if node.name == "ground" || node.name == "obstacle" {
// ...
}
}
"*"
means you'll enumerate over all nodes that are children of the scene (assuming it's the scene calling enumerateChildNodesWithName
). If you wanted to check all nodes you would instead use "//*"
.
Upvotes: 6