cocos2d-x基本知识点:声音
2014-09-18 01:40
225 查看
预加载声音和设置音量:
SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(CCFileUtils::sharedFileUtils()->
fullPathFromRelativePath(MUSIC_FILE));
SimpleAudioEngine::sharedEngine()->preloadEffect(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(MUSIC_FILE));
SimpleAudioEngine::sharedEngine()->setEffectsVolume(0.5);
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);
对声音的操作:
void CocosDenshionTest::menuCallback(CCObject* pSender){
CCMenuItem* pMenuItem = (CCMenuItem*)pSender;
int nIdx = pMenuItem->getZOrder() - 1000;
switch(nIdx){
case 0://播放背景音乐
SimpleAudioEngine::sharedEngine()->playBackgroundMusic(std::string(CCFileUtils::sharedFileUtils()
->fullPathFromRelativePath(MUSIC_FILE)));
break;
case 1://停止背景音乐
SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
break;
case 2://暂停背景音乐
SimpleAudioEngin::sharedEngine()->pauseBackGroundMusic();
break;
case 3://恢复背景音乐
SimpleAudioEngin::sharedEngine()->resumeBackgroundMusic();
break;
case 4://回放背景音乐
SimpleAudioEngine::sharedEngine()->rewindBackgroundMusic();
break;
case 5://控制台打印是否正在播放背景音乐
if(SimpleAudioEngine::sharedEngine()-isBackgroundMusicPlaying()){
CCLog("background music is playing");
}
else{
CCLog("background music is not playing");
}
break;
case 6://播放音效,不循环播放
m_nSoundId = SimpleAudioEnine::sharedEngine()->playEffect(std::string(CCFileUtils::sharedFileUtils()->
fullPathFromRelativePath(EFFECT_FILE)).c_str());
break;
case 7://播放音效,循环播放
m_nSoundId = SimpleAudioEngine::sharedEngine()->playEffect(std::string(CCFileUtils::sharedFileUtils()->
fullPathRelativePath(EFFECT_FILE)).c_str(),true);
break;
case 8://停止播放音效
SimpleAudioEngine::sharedEngine()->stopEffect(m_nSoundId);
break;
case 9://从缓存中删除音效
SimpleAudioEngine::sharedEngine()->unloadEffect(std::string(CCFileUtils::sharedFileUtils()->
fullPathFromRelativePath(EFFECT_FILE)).c_str());
break;
case 10://提高背景音乐音量
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->
getBackgroundMusicVolume()+0.1f);
break;
case 11://降低背景音乐音量
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->
getBackgroundVolume()-0.1f);
break;
case 12://提高音效音量
SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume()+0.1f);
break;
case 13://降低音效音量
SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume()+0.1f);
break;
case 14://暂停音效
SimpleAudioEngine::sharedEngine()->pauseEffect(m_nSoundId);
break;
case 15://恢复音效
SimpleAudioEngine::sharedEngine()->resumeEffect(m_nSoundId);
break;
case 16://暂停所有音效
SimpleAudioEngine::sharedEngine()->pauseAllEffects();
break;
case 17://恢复所有音效
SimpleAudioEngine::sharedEngine()->resumeAllEffects();
break;
case 18://停止所有音效
SimpleAudioEngine::sharedEngine()->stopAllEffects();
break;
}
相关文章推荐
- cocos2d-x基本知识点(7):动画
- cocos2d-x基本知识点(1)
- cocos2d-x基本知识点(5)
- cocos2d-x基本知识点(6)---动作系列(下)
- cocos2d-x基本知识点(3)
- cocos2d-x基本知识点(6)---动作系列(上)
- cocos2d-x基本知识点(2)
- cocos2d-x基本知识点(6)---动作系列(中)
- cocos2d-x基本知识点:事件处理机制之加速度传感器事件
- cocos2d-x基本知识点(4)
- cocos2d-x基本知识点:文本渲染
- cocos2d-x基本知识点:按键事件
- cocos2d-x基本知识点(6)---动作系列(end)
- cocos2d-x基本知识点:事件处理机制之触屏事件1
- cocos2d-x基本知识点:游戏存档
- cocos2d-x基本知识点(8):菜单项
- cocos2d-x基本知识点:网络连接libcurl
- cocos2d-x基本知识点:事件处理机制之触屏事件2
- cocos2d-x基本知识点:粒子系统
- web安全测试的基本知识点