O'Reilly logo

Building Android Games with Cocos2d-x by Raydelto Hernandez

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 mute button to our game

Before ending this chapter, we are going to add a mute button to our game so that we can simply set our sound effects and our background music volume to zero in a single touch.

In order to achieve this, we are going to add two methods to the HelloWorld class; one for initializing the buttons and the other for actually muting all the sounds.

In order to achieve this, we are going to add the following lines to our HelloWorldScene.h header file under the private section:

int _musicId;
cocos2d::MenuItemImage* _muteItem;
cocos2d::MenuItemImage* _unmuteItem;
void initMuteButton();
void muteCallback(cocos2d::Ref* pSender);

Now, we are going to add the initMuteButton implementation code to the HelloWorldScene.cpp file as follows: ...

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