这篇文章中,我们简单介绍下cocos2dx中播放音乐的类,SimpleAudioEngine,游戏中音乐主要是背景音乐,跟短的音效,OK,直接上代码:
//预加载 SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic("music_logo.mp3"); //播放背景音乐 SimpleAudioEngine::sharedEngine()->playBackgroundMusic("music_logo.mp3", true); //暂停播放 SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); //停止播放,还有一个函数带一个参数,表示是否释放该资源 SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(); //设置音量,0.0-1.0 SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5); //播放音效 SimpleAudioEngine::sharedEngine()->playEffect("sound_button.mp3"); //暂停某个音效 SimpleAudioEngine::sharedEngine()->pauseEffect(unsigned int nSoundId); //暂停全部音效 SimpleAudioEngine::sharedEngine()->pauseAllEffects(); //停止某个音效 SimpleAudioEngine::sharedEngine()->stopEffect(unsigned int nSoundId); //停止所有音效 SimpleAudioEngine::sharedEngine()->stopAllEffects(); //在程序不需要音乐时,释放sharedEngine() SimpleAudioEngine::sharedEngine()->end();
OK,就这么简单呐~~~~
csdn:http://blog.csdn.net/kuloveyouwei