How to remove all nodes with a specific name spritekit

Viewed 609

Is there a simple way to remove all spritekit nodes with a given name. I am making a project that has waves of spaceships and at a certain score, I want the old spaceships to dissappear so that new, harder spaceships replace them. I gave all of the level one spaceships the same name and was wondering if there was a way that I could remove them all based on this factor.

1 Answers

It depends on how you created the spaceships. If you made them all with the same name maybe you can try:

self.enumerateChildNodesWithName("spaceShip"){

    spaceShip.removeFromParent()
}
//or try 
for child in self.children{

    if child.name == "spaceShip"{
        child.removeFromParent
    }
}
Related