cocos2dx音樂與音效

來源:互聯網
上載者:User

標籤:style   os   io   cti   re   c   

// 預先載入音樂和音效

SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile("fashu1.wav","fashu1.wav"));

SimpleAudioEngine::sharedEngine()->preloadEffect(CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile("fashu1.wav","fashu1.wav"));


// 設定預設音量
SimpleAudioEngine::sharedEngine()->setEffectsVolume(0.5);
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);

 

// 播放背景音樂

SimpleAudioEngine::sharedEngine()->playBackgroundMusic(CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile("fashu1.wav","fashu1.wav")); 

// 停止背景音樂

SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();

// 暫停背景音樂

SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();

// 繼續播放背景音樂

SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();

// 後退背景音樂

SimpleAudioEngine::sharedEngine()->rewindBackgroundMusic();

// 背景音樂是否現正播放

if (SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())

{ CCLOG("現正播放"); }

else CCLOG("沒在播放");

// 播放音效,並且得到此音效的ID

SimpleAudioEngine::sharedEngine()->playEffect(CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile("fashu1.wav","fashu1.wav"));

// 重複播放音效

SimpleAudioEngine::sharedEngine()->playEffect(std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(MUSIC_FILE)).c_str(), true);

// 停止播放音效

SimpleAudioEngine::sharedEngine()->stopEffect(effectId);

// 釋放音效

SimpleAudioEngine::sharedEngine()->unloadEffect (std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(MUSIC_FILE)).c_str() );

// 增加背景音樂音量

SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume()+0.1f);

// 減少背景音樂音量

SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume()-0.1f);

// 增加背景音效音量

SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume()+0.1f);

// 減少背景音效音量

SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume()-0.1f);

// 暫停音效

SimpleAudioEngine::sharedEngine()->pauseEffect(effectId);

// 繼續 播放音效

SimpleAudioEngine::sharedEngine()->resumeEffect(effectId);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.