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