Stop playing background music in Cocos2d-x
Where can I choose to stop playing background music? For example, in the HelloWorld scenario, the main code is as follows:
Bool HelloWorld: init () {return true;} void HelloWorld: onEnter () {Layer: onEnter (); log ("HelloWorldonEnter");} voidHelloWorld :: onEnterTransitionDidFinish () {Layer: onEnterTransitionDidFinish (); log ("HelloWorldonEnterTransitionDidFinish");} void HelloWorld: onExit () {Layer: onExit (); log ("HelloWorldonExit"); // stop playing code ①} voidHelloWorld: onExitTransitionDidStart () {Layer: onExitTransitionDidStart (); log ("HelloWorldonExitTransitionDidStart "); // stop playback code ②} void HelloWorld: cleanup () {Layer: cleanup (); log ("HelloWorldcleanup"); // stop playback code ③}
In theory, we can stop playing background music with the following code: SimpleAudioEngine: getInstance ()-> stopBackgroundMusic ("sound/jazzaudio ") place it in three locations (①, ②, and ③ In the code ). Next we will analyze their differences separately.
1. Place the code in rows ① and ②.
Put the code in rows ① and ② (that is, in the HelloWorld: init function). If you call the background music function in a later scenario, the background music is abnormal. We have discussed this issue in the previous section.
2. Place the Code in line ③
Put the code in row ③ (that is, in the HelloWorld: cleanup function). This function is called when the layer object is cleared. It is better to stop playing background music here.
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