Stop playing background music in Cocos2d-x

Source: Internet
Author: User

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

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.