Steve Ives
Steve Ives

Reputation: 8134

Pause everything except animation of one node?

I am writing a clone of the old Space Invaders game. The invaders are moved during update() and drop bombs randomly; the player ship moves when the screen is touched. If an invader bomb hits the player, I want everything to stop except for the player's ship death animation. Once this is complete, I want everything to start again.

What the best way to achieve this? I considered enumerating over all nodes, setting the paused property to true; adding a check in update() to see if the death animation was running on the player and skip movement if it was and similarly ignoring user input if the animation was running.

Another approach would have been to have a world node of which everything is a child. I could then pause the world node and add a copy of the player's ship to the scene which runs the animation, making it look like everything has stopped except the player's ship death animation.

Both these seem a lot of work for the effect I want. Any suggestions?

Upvotes: 2

Views: 143

Answers (1)

Alessandro Ornano
Alessandro Ornano

Reputation: 35392

You could make two invisible ,rootNode where your enemies, your objects and all your game enviroments (labels, coins..) are childs:

self.rootNode.addChild(enemy1)

and another rootShipNode where you have added your player. With this approach you can stop all when you pause self, or put in pause the invisible nodes whenever you want.

You can adopt this process to add also a pauseNode (SKNode) to your scene:

var pauseNode: SKNode! // a node with resume, go to menu, buttons
self.addChild(pauseNode)

When you press your pause button, you can open your pauseNode and launch:

self.rootNode.paused = true
self.rootPlayerNode.paused = true

but all animations and object added to self, pauseNode elements and animations included, are in running.

Upvotes: 2

Related Questions