pulitr pulitr - 5 months ago 35
iOS Question

Removing all copies of the SKSpriteNode - Swift

In loop I have this line and I need to remove all copies. Can you help me how to do ? I do in Swift in SpriteKit. Please help me.

obstacles = obstaclesImage.copy() as! SKSpriteNode

Answer

Name your nodes:

obstacleCopy.name = "obstacleCopy"

Then enumerate their parent:

self.enumerateChildNodesWithName("enemy") {
    node, stop in 
    if node.name == "obstacleCopy"  { node.removeFromParent()}
}