Game Programming Tutorial – Beginners Action Game
Resetting The Game
The first thing we are do here is add a classwide boolean variable so that this code will not execute multiple times so place this code in the interface in the Game.h file.
The reason I added this was because if multiple balloons exit the screen at the same time the movementThroughTopOfScreen method is executed multiple times.
Now add this if statement into the movementThroughTopOfScreen method.
{
resetButtonVisible = YES;
The reason I added this was because if multiple balloons exit the screen at the same time the movementThroughTopOfScreen method is executed multiple times.
Now we’re going to add a semi-transparent image covering the screen.
[playFieldSprite addChild:backgroundImage];
An added side effect of running this code is that touches are prevented from reaching any ballons.
Now we’re going to add a button to the center of the screen.
resetButton.x = self.width/2-resetButton.width/2;
resetButton.y = self.height/2-resetButton.height/2;
resetButton.fontName = @"Marker Felt";
resetButton.fontSize = 20;
resetButton.text = @"Reset Game";
Notice that in creating this button we needed to provide an image, however the animation causing the image to shrink is all built in to the Sparrow Framework. As you can see the properties of buttons are very similar to text fields.
Now we’re going to add an event listener to the button.
forType:SP_EVENT_TYPE_TRIGGERED];
The triggered event occurs when the button is pressed.
Add the button to the playing field with this code:
Now we’re going to create the onResetButtonTriggered event which runs when the button is pressed.
This method is pretty simple we just clear the screen, and then make things just as they were when the game first started.
And that’s the end, when you run this tutorial you should see a reset button and be able to restart the game after a ballon exits through the top of the screen like in the screenshot below:

You can download the completed project here with extensive comments in the Game implementation file.
I hope you enjoyed this tutorial please re-tweet and share it by using the buttons below. If you have any questions then please enter them in the comments below. I’d also love to here what you’d like to see next with this (menu, highscores, powerups?). Thanks.
Twitter Comments
Submit A Resource
Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?
You can submit the url here.
The resources we feel will appeal to our readers the most will be posted on the front page.
