Book Image

Learning Cocos2d-x Game Development

By : Siddharth Shekar
Book Image

Learning Cocos2d-x Game Development

By: Siddharth Shekar

Overview of this book

Table of Contents (19 chapters)
Learning Cocos2d-x Game Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Creating the pause button and showing the pause screen


We are going to add a pause button to the HUDLayer so that when the pause button is clicked, the game will be paused, and we will also add a resume button so that the game can be resumed.

For this, in the HUDLayer.h file, create two new variables named pauseMenu and resumeMenu of the CCMenu type:

    CCMenu* pauseMenu;
    CCMenu* resumeMenu;

Also, create two new functions named pauseGame() and resumeGame():

    void pauseGame(CCObject* pSender);
    void resumeGame(CCObject* pSender);

Paste the _bookgame_UI__pause.png and _bookgame_UI__resume.png files to the Resources folder of the project in your system.

In the HUDLayer.cpp file in the constructor, create the pauseMenuItemImage variable and add it to the pauseMenu variables:

    CCMenuItemImage*pauseItem = CCMenuItemImage::create("_bookgame_UI__pause.png",
                                                         "_bookgame_UI__pause.png", this,
                                          ...