Tutorial Cocos2d Create Your Simple Game – 6: Adding “Pause Game”

This time the tutorial will be really simple, we are will add a “Pause Screen” to our game. This tutorial is following the “Create Your Simple Game” tutorial, I recommend you to be following from the FIRST tutorial HERE. Or check my PREVIEW Tutorial HERE. But if you are here only for the “Pause”, it’s okay, any problems comment. 🙂

Adding a Pause Button

First of all we will need a “Pause Button“. Right click over the image bellow and “Save As” with the name of “pause.png”:

Add the this image “pause.png” to your “Resources/” group in XCode. (Drag and drop the file in the “Resources”)

Before we add the code to create the button inside of the init, we must import a new “Class”:

#import “PauseScene.h”

An error will show cause you yet didn’t create the PauseScene node.

Now with our “Pause Button”, we will add it to our Game Screen, so go to Game.m and inside of “-(id) init{}“:

If anyone gets “itemFromString:target:selector:’is deprecated” just change the From to With and it will be fine. The same goes for this line of code “CCMenuItem *Pause = [CCMenuItemImage itemFromNormalImage:@”pause.png” just change itemFromNormalImage to itemWithNormalImage.

Great tutorial but how would one specify a location of a pause button that pauses a game?