cocos2d-x 游戏中声音 有两种 一种是背景音乐 一种是音效 加载音乐 或者音效的时候 我们需要先缓存声音 #define EFFECT_FILE "effect1.wav" //音效 #define MUSIC_FILE "background.mp3" //音乐 这两个宏 代表了 音乐和音效的
名称或者目录 SimpleAu
dioEngine::sharedEngine()->preloadBackgroundMusic( CCFileUtils::sharedFileUtils()->fullPathFr
omrelativePath(MUSIC_FILE) );//缓存音乐 SimpleAu
dioEngine::sharedEngine()->preloadEffect( CCFileUtils::sharedFileUtils()->fullPathFr
omrelativePath(EFFECT_FILE) );//缓存音效 // set default volume SimpleAu
dioEngine::sharedEngine()->setEffectsVolume(0.5);//设置音效声音 SimpleAu
dioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);//设置音乐声音 1.播放背景音乐 SimpleAu
dioEngine::sharedEngine()->playBackgroundMusic(std::string(CCFileUtils::sharedFileUtils()->fullPathFr
omrelativePath(MUSIC_FILE)).c_
str(),true); 2.也可以判断目前有没有背景音乐 if (SimpleAu
dioEngine::sharedEngine()->isBackgroundMusicPlaying()) {
cclOG("背景音乐正在播放"); } else {
cclOG("没有背景音乐播放"); } 3.停止背景音乐 SimpleAu
dioEngine::sharedEngine()->stopBackgroundMusic(); 4.暂停背景音乐 SimpleAu
dioEngine::sharedEngine()->pauseBackgroundMusic(); 5.恢复背景音乐 SimpleAu
dioEngine::sharedEngine()->resumeBackgroundMusic(); 6.重头
调用背景音乐 SimpleAu
dioEngine::sharedEngine()->rewindBackgroundMusic(); 音效部分 1.
播放音效 m_nSoundId = SimpleAu
dioEngine::sharedEngine()->playEffect(std::string(CCFileUtils::sharedFileUtils()->fullPathFr
omrelativePath(EFFECT_FILE)).c_
str()); 2.重复
播放音效 m_nSoundId = SimpleAu
dioEngine::sharedEngine()->playEffect(std::string(CCFileUtils::sharedFileUtils()->fullPathFr
omrelativePath(EFFECT_FILE)).c_
str(),true); 3.停止
播放音效 SimpleAu
dioEngine::sharedEngine()->stopEffect(m_nSoundId); 4.卸载音效 SimpleAu
dioEngine::sharedEngine()->unloadEffect(std::string(CCFileUtils::sharedFileUtils()->fullPathFr
omrelativePath(EFFECT_FILE)).c_
str()); 5.暂停音效 SimpleAu
dioEngine::sharedEngine()->pauseEffect(m_nSoundId); 6.恢复音效 SimpleAu
dioEngine::sharedEngine()->resumeEffect(m_nSoundId); 7.暂停所有音效 SimpleAu
dioEngine::sharedEngine()->pauseAllEffects(); 8.恢复所有音效 SimpleAu
dioEngine::sharedEngine()->resumeAllEffects(); 9.停止所有音效 SimpleAu
dioEngine::sharedEngine()->stopAllEffects();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。