Cocos2dx3.1.1 how to play a sound

Source: Internet
Author: User

1. Load

Cocosdenshion: simpleaudioengine: sharedengine ()-> preloadbackgroundmusic ("music. Mid ");

Cocosdenshion: simpleaudioengine: sharedengine ()-> preloadeffect ("pew-pew-lei.wav ");

These two sentences read the background music files and audio files respectively.

2. Play

Cocosdenshion: simpleaudioengine: sharedengine ()-> playbackgroundmusic ("music. Mid", true );

Cocosdenshion: simpleaudioengine: sharedengine ()-> playeffect ("pew-pew-lei.wav ");

These two sentences are playing music and sound effects respectively.

3. Stop

Cocosdenshion: simpleaudioengine: sharedengine ()-> stopbackgroundmusic (false );

This is to stop playing music.

There are also pause and other related interfaces, but I cannot recover after testing the pause in Win32. I don't know why. You can check the header file of this class by yourself, and there are very few interfaces.

// Pre-load background music
// Cocosdenshion: simpleaudioengine: sharedengine ()-> preloadbackgroundmusic ("kerberhuoworkflow ");
// Play background music
// Cocosdenshion: simpleaudioengine: sharedengine ()-> playbackgroundmusic ("invalid huoworkflow", true );


When the program does not need music, it needs to call simpleaudioengine: sharedengine ()-> end (); release sharedengine ().


Other functions related to Playing Sound Effects

Simpleaudioengine: sharedengine ()-> stopbackgroundmusic (); // stop the background music. A boolean parameter can be used to indicate whether to release the music file.
Simpleaudioengine: sharedengine ()-> pausebackgroundmusic (); // pause background music
Simpleaudioengine: sharedengine ()-> rewindbackgroundmusic (); // call background music again
Simpleaudioengine: sharedengine ()-> isbackgroundmusicplaying () // return the Boolean parameter to check whether background music is playing.
Simpleaudioengine: sharedengine ()-> setbackgroundmusicvolume (0.5); // set the volume to 0.0-1.0 </span>


<Span style = "font-family: Microsoft yahei; font-size: 18px;"> preloadeffect ();
Playeffect ();
Stopeffect (); // stop the sound effect. You can choose to stop a sound effect independently and stop it with the m_nsoundid
Stopalleffects (); // stop all sound effects
Pauseeffect (m_nsoundid); // pause a single sound effect
Resumeeffect (m_nsoundid); // start the sound effect again
Pausealleffects (); // pause all sound effects
Resumealleffects (); // start all sound effects again
Seteffectsvolume (0.5); // sets the sound volume.
Unloadeffect (STD: string (ccfileutils: fullpathfromrelativepath (effect_file). c_str (); // uninstall sound effects </span>


Cocos2dx3.1.1 how to play a sound

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.