您的位置:首页 > 移动开发 > Cocos引擎

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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: