cocos2d-x引擎添加音乐

前端之家收集整理的这篇文章主要介绍了cocos2d-x引擎添加音乐前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一:在.cpp中添加文件 //cpp with cocos2d-x #include"SimpleAudioEngine.h" 二:在init()里添加背景音乐 //cpp with cocos2d-x CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic( "background-music-aac.wav",true); 三:添加特效: //cpp with cocos2d-x CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect( "pew-pew-lei.wav"); 四:还有一些其他操作,包括pause,stop等: backGround: // stop background music case 1: SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(); break; // pause background music case 2: SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); break; // resume background music case 3: SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); break; // rewind background music case 4: SimpleAudioEngine::sharedEngine()->rewindBackgroundMusic(); break; Effect: // stop effect case 8: SimpleAudioEngine::sharedEngine()->stopEffect(m_nSoundId); break; // unload effect case 9: SimpleAudioEngine::sharedEngine()->unloadEffect(std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(EFFECT_FILE)).c_str()); break; // add bakcground music volume case 10: SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume() + 0.1f); break; // sub backgroud music volume case 11: SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume() - 0.1f); break; // add effects volume case 12: SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume() + 0.1f); break; // sub effects volume 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(); 五:注意! 1、音乐格式要注意,像在pc机上wav,mp3是可以用的,ogg那是肯定不可以的。 2、开始播放音乐后,即使你切换场景,音乐还是在播放。所以需要在切换场景的同时把音乐关上。

原文链接:https://www.f2er.com/cocos2dx/346761.html

猜你在找的Cocos2d-x相关文章