Pause and continue playing background music in Cocos2d-x

Source: Internet
Author: User

Pause and continue playing background music in Cocos2d-x
It seems that we seldom use the pause and continue operations of background music. In fact, this is also the case. The example code of pause and continue operations of background music is as follows:

SimpleAudioEngine::getInstance()->pauseBackgroundMusic();SimpleAudioEngine::getInstance()->resumeBackgroundMusic();

Generally, they call the pause function resumeBackgroundMusic () when the game returns to the background, and then call the Resume function pauseBackgroundMusic () when you return to the foreground (). The Code should be placed in the game lifecycle function, as shown in the following code.

voidAppDelegate::applicationDidEnterBackground() {   Director::getInstance()->stopAnimation();   SimpleAudioEngine::getInstance()->pauseBackgroundMusic();                                              ①}voidAppDelegate::applicationWillEnterForeground() {   Director::getInstance()->startAnimation();   SimpleAudioEngine::getInstance()->resumeBackgroundMusic();                                            ②}

The applicationDidEnterBackground function is a callback function when the game enters the background. In this function, we often need to pause playing all background music (see line 1 of the Code ). The applicationWillEnterForeground is called back when the game returns to the front-end. In this function, we often need to continue playing background music (see line ② of the Code ).


More content please pay attention to the Cocos2d-x series of books "Cocos2d-x practice (Volume I): C ++ development" book exchange discussion site: http://www.cOcoagame.netWelcome to cocos2d-x Technology Discussion Group: 257760386, 327403678


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.