概述转载自http://blog.sina.com.cn/s/blog_7d1531ed0101ak0e.html #defineEFFECT_FILE "effect1.wav" //
音效 #define MUSIC_FILE "background.mp3" //
音乐 这两个宏代表了 音乐和音效的名称或者目录 SimpleAudioEngine::sharedEngine(
转载自http://blog.sina.com.cn/s/blog_7d1531ed0101ak0e.HTML
#defineEFFECT_file "effect1.wav"//音效
#define MUSIC_file "background.mp3"//音乐
这两个宏代表了 音乐和音效的名称或者目录
SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(CCfileUtils::sharedfileUtils()->fullPathFromrelativePath(MUSIC_file));//缓存音乐
SimpleAudioEngine::sharedEngine()->preloadEffect(CCfileUtils::sharedfileUtils()->fullPathFromrelativePath(EFFECT_file));//缓存音效
//set default volume
SimpleAudioEngine::sharedEngine()->setEffectsVolume(0.5);//设置音效声音
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);//设置音乐声音
1.播放背景音乐
SimpleAudioEngine::sharedEngine()->playBackgroundMusic(std::string(CCfileUtils::sharedfileUtils()->fullPathFromrelativePath(MUSIC_file)).c_str(),true);
2.也可以判断目前有没有背景音乐
if (SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
{
cclOG("背景音乐正在播放");
}
else
{
cclOG("没有背景音乐播放");
}
3.停止背景音乐
SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
4.暂停背景音乐
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
5.恢复背景音乐
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
6.重头调用背景音乐 SimpleAudioEngine::sharedEngine()->rewindBackgroundMusic();
音效部分
1.播放音效
m_nSoundID = SimpleAudioEngine::sharedEngine()->playEffect(std::string(CCfileUtils::sharedfileUtils()->fullPathFromrelativePath(EFFECT_file)).c_str());
2.重复播放音效 m_nSoundID = SimpleAudioEngine::sharedEngine()->playEffect(std::string(CCfileUtils::sharedfileUtils()->fullPathFromrelativePath(EFFECT_file)).c_str(),true);
3.停止播放音效
SimpleAudioEngine::sharedEngine()->stopEffect(m_nSoundID);
4.卸载音效
SimpleAudioEngine::sharedEngine()->unloadEffect(std::string(CCfileUtils::sharedfileUtils()->fullPathFromrelativePath(EFFECT_file)).c_str());
5.暂停音效
SimpleAudioEngine::sharedEngine()->pauseEffect(m_nSoundID);
6.恢复音效
SimpleAudioEngine::sharedEngine()->resumeEffect(m_nSoundID);
7.暂停所有音效
SimpleAudioEngine::sharedEngine()->pauseAllEffects();
8.恢复所有音效
SimpleAudioEngine::sharedEngine()->resumeAllEffects();
9.停止所有音效
SimpleAudioEngine::sharedEngine()->stopAllEffects()
总结
以上是内存溢出为你收集整理的cocos2d-x (音效-音乐)SimpleAudioEngine全部内容,希望文章能够帮你解决cocos2d-x (音效-音乐)SimpleAudioEngine所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)