cocos2d-x引擎添加音乐

cocos2d-x引擎添加音乐,第1张

概述一:在.cpp中添加头文件 //cpp with cocos2d-x #include"SimpleAudioEngine.h" 二:在init()里添加背景音乐 //cpp with cocos2d-x CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic( "background-music-aac.wav"

一:在.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、开始播放音乐后,即使你切换场景,音乐还是在播放。所以需要在切换场景的同时把音乐关上。

总结

以上是内存溢出为你收集整理的cocos2d-x引擎添加音乐全部内容,希望文章能够帮你解决cocos2d-x引擎添加音乐所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1005201.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存