Book Image

Cocos2d-x Cookbook

By : Akihiro Matsuura
Book Image

Cocos2d-x Cookbook

By: Akihiro Matsuura

Overview of this book

Table of Contents (18 chapters)
Cocos2d-x Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Pausing and resuming background music


This recipe will help you better understand the concept of pausing and resuming background music.

How to do it...

It is very easy to stop or pause the background music. You don't specify the argument by using these methods. The code for stopping the background music is as follows:

auto audio = CocosDenshion::SimpleAudioEngine::getInstance();
// stop the background music
audio->stopBackgroundMusic();

Code for pausing:

// pause the background music 
audio->pauseBackgroundMusic();

Code for resuming the paused background music:

// resume the background music 
audio->resumeBackgroundMusic();

How it works...

You can stop the background music that is playing by using the stopBackgroundMusic method. Alternatively, you can pause the background music by using the pauseBackgroundMusic method. Once you stop it, you can play it again by using the playBackgroundMusic method. Further, if you pause it, you can resume playing the music by using the resumeBackgroundMusic...