pulitr pulitr - 5 months ago 11
iOS Question

Removing all copies of the SKSpriteNode

In loop I have this line and I need to remove all copies. How would I be able to do this in Swift in SpriteKit?

obstacles = obstaclesImage.copy() as! SKSpriteNode

Answer

Name your nodes:

obstacleCopy.name = "obstacleCopy"

Then enumerate their parent:

self.enumerateChildNodesWithName("obstacleCopy") {
    node, stop in 
    node.removeFromParent()
}