O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a pause and resume button

It is always better to add a pause button to your game so that if the player receives a call, he/she can pause the game and resume it later on.

Getting started

Import pauseBtnOFF.png and pauseBtnON.png into the project directory for this section.

How to do it…

In the newly renamed GameplayScene.m file, we will add the following code at the end of the init function:

//pause button
    CCButton *pauseBtn = [CCButton buttonWithTitle:nil
      spriteFrame:[CCSpriteFrame frameWithImageNamed:@"pauseBtnOFF.png"]
      highlightedSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"pauseBtnON.png"]
      disabledSpriteFrame:nil];


    [pauseBtn setTarget:self selector:@selector(pauseBtnPressed:)];

    pauseBtn.togglesSelectedState = YES;


 CCLayoutBox ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required