simplicity is Always the best idea

After struggling with new Scenes, and trying to figure out how to cleanly handle having a pause screen, I decided to step back and look at it a different way.

What do I really want to achieve?

Show a new layer, with some options on it (like continue, restart, choose a level)

so why am I messing around with scenes? well, the reason was because I thought thats how it should be done. But why can’t I just shove a pause layer on top of the game?

That’s what I just did – and it works much better, with much less code.

the only thing it doesn’t do is transitions – which if I want them, I am sure I could fake up anyway!

So I introduced a pauseGame() function…

void GameController::pauseGame()
	Globals::holdTouchFunctions = true;
	Globals::gamePaused = true;

stopAllFunctions is just a method that stops any of the user-functions (jumping, pooping etc.) that have started already; this is important if the user presses Fart and pause – or we will hear farting int eh pause screen!

holdTouchFunctions is just a flag to see if touches are going to be processed in the game. As I use areas of the screen for control, I need to disable this when paused to avoid the pig trying to jump if that area of the screen is touched.

gamePaused is a flag that I check in the main update() method – if true, I do nothing, so nothing gets updated! Simples!

I have a corresponding unPauseGame() method too – just sets the flags to false and calls scheduleUpdate.

I had a real problem when paused that, despite resetting all physical objects, my box2d object seemed to magically retain some residual velocity.
I gave up after a while and resorted to setting it back to zero in the update method – it’s only used in debug mode when I’m editing – so no real overhead.

Leave a Reply

Your email address will not be published. Required fields are marked *