[Cocos2d-x entry practice] WeChat aircraft war 14: background music and sound

Source: Internet
Author: User

Original Work, reprinted, please mark:

Android: on android, CocosDenshion supports the audio format that corresponds to the format supported by android. media. MediaPlayer. IOS: The formats supported by CocosDenshion in the Cocos2d-x on IOS are the same as those supported in the Cocos2d-iphone, and mp3, caf is the recommended format. Windows:. mid,. wav are supported. Note that mp3 is not supported. Marmalade: mp3


# Include "SimpleAudioEngine. h" using namespace CocosDenshion; // if this step is missing, SimpleAudioEngine cannot be found.

 CocosDenshion::SimpleAudioEngine

SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("sound/game_music.mp3");

SimpleAudioEngine: sharedEngine ()-> playBackgroundMusic ("sound/game_musicloud", true); // start playing background music. true indicates loop SimpleAudioEngine: sharedEngine () -> stopBackgroundMusic (); // stop the background music. This is a default parameter function. Passing a parameter indicates whether to release the music file SimpleAudioEngine: sharedEngine ()-> pauseBackgroundMusic (); // pause background music SimpleAudioEngine: sharedEngine ()-> rewindBackgroundMusic (); // call background music SimpleAudioEngine: sharedEngine ()-> isBackgroundMusicPlaying () // return a Boolean parameter indicating whether the background music SimpleAudioEngine: sharedEngine ()-> setBackgroundMusicVolume (0.5) is being played. // set the volume to 0.0-1.0

SimpleAudioEngine::sharedEngine()->preloadEffect("sound/bullet.mp3");
SimpleAudioEngine: sharedEngine ()-> playEffect ("sound/bulletask", false); // start playing background sound effects. false indicates no loop SimpleAudioEngine: sharedEngine () -> stopEffect (m_nSoundId); // you can choose to stop a sound effect independently. The value is SimpleAudioEngine: sharedEngine ()-> stopAllEffects () returned by playEffect (); // stop all sound effects SimpleAudioEngine: sharedEngine ()-> pauseEffect (m_nSoundId); // pause a single sound effect SimpleAudioEngine: sharedEngine ()-> resumeEffect (m_nSoundId ); // restart the sound effects SimpleAudioEngine: sharedEngine ()-> pauseAllEffects (); // pause all sound effects SimpleAudioEngine: sharedEngine ()-> resumeAllEffects (); // re-start all sound effects SimpleAudioEngine: sharedEngine ()-> setEffectsVolume (0.5); // set the sound volume 0.0-1.0 SimpleAudioEngine: sharedEngine () -> unloadEffect ("sound/bulletask"); // uninstall the sound effect.

static EffectList s_List;

void SimpleAudioEngine::end()

void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath){}

void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop){    if (! pszFilePath)    {        return;    }    sharedMusic().Open(_FullPath(pszFilePath), _Hash(pszFilePath));    sharedMusic().Play((bLoop) ? -1 : 1);}


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.