【cocos2d-x入門實戰】微信飛機大戰之十四:背景音樂和音效

來源:互聯網
上載者:User

原創作品,轉載請標明:

Android:在android上CocosDenshion能支援的音頻格式是對應於android.media.MediaPlayer所支援的格式。iOS:在IOS上面Cocos2d-x的CocosDenshion所支援的格式和Cocos2d-iphone中所支援的是一樣,mp3,caf是推薦的格式。windows:.mid, .wav are supported. Note that mp3 is not supported.Marmalade:mp3


 #include "SimpleAudioEngine.h" using namespace CocosDenshion;//很多人少了這一步導致找不到SimpleAudioEngine

 CocosDenshion::SimpleAudioEngine

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

SimpleAudioEngine::sharedEngine()->playBackgroundMusic("sound/game_music.mp3",true);//開始播放背景音樂,true表示迴圈SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();//停止背景音樂,這是一個預設參數函數,傳參表示是否釋放音樂檔案SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();//暫停背景音樂SimpleAudioEngine::sharedEngine()->rewindBackgroundMusic();//重頭調用背景音樂SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()//返回布爾型參數,表示是否在放著背景音樂SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);//設定音量0.0-1.0

SimpleAudioEngine::sharedEngine()->preloadEffect("sound/bullet.mp3");
SimpleAudioEngine::sharedEngine()->playEffect("sound/bullet.mp3",false);//開始播放背景音效,false表示不迴圈SimpleAudioEngine::sharedEngine()->stopEffect(m_nSoundId);//停止音效,可以選擇單獨停掉一個音效,這個值是由playEffect返回的SimpleAudioEngine::sharedEngine()->stopAllEffects();//停止全部音效SimpleAudioEngine::sharedEngine()->pauseEffect(m_nSoundId);//暫停單個音效SimpleAudioEngine::sharedEngine()->resumeEffect(m_nSoundId);//重新開始音效SimpleAudioEngine::sharedEngine()->pauseAllEffects();//暫停全部音效SimpleAudioEngine::sharedEngine()->resumeAllEffects();//重新開始全部音效SimpleAudioEngine::sharedEngine()->setEffectsVolume(0.5);//設定音效音量0.0-1.0SimpleAudioEngine::sharedEngine()->unloadEffect("sound/bullet.mp3");//卸載音效

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);}


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.