概述typedef struct { unsigned int soundId; const char* soundFilePath; }Sound; typedef struct { const char* musicFilePath; } Music; /* * 注意,Andoird下面只支持.ogg * */
typedefstruct{ unsignedintsoundID; const
char*soundfilePath; }Sound; char*musicfilePath; }Music; /* *注意,Andoird下面只支持.ogg * */
static
MusicbgMusic= { "audio/mainbgmusic.ogg" }; static
SoundtestSound= 0, "audio/clicksound.ogg" }; class
AudioManager public
: /*注意,此方法在进入游戏前调用*/
static
voIDinit(); /*预加载*/
voID
preLoadBgMusic(Music&music); voID
preLoadSound(Sound&sound); /*播放*/
voID
playMusic(Music&music,boolloop=true); voID
playSound(Sound&sound,153); background-color:inherit; Font-weight:bold">false); /*暂停*/
voID
pauseMusic(Music&music); voID
pauseSound(Sound&sound); /*停止*/
voID
stopMusic(Music&music,87); background-color:inherit; Font-weight:bold">boolrelease=voIDstopSound(Sound&sound); voID
stopAllSound(); /*恢复*/
voID
resumeMusic(); /*全部结束*/
voID
end(); </pre><br> <pre></pre> <br> <prename="code"class="cpp"><prename="code"class="cpp">voIDAudioManager::init() { /*例子*/
preLoadBgMusic(bgMusic); preLoadSound(testSound); } /********************************************************* 一些方法的
封装 *********************************************************/
voID
AudioManager::preLoadBgMusic(Music&music) using
namespaceCocosDenshion; namespace
cocos2d; music.musicfilePath=CCfileUtils::sharedfileUtils()->fullPathFromrelativePath(music.musicfilePath); cclOG(music.musicfilePath); SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(music.musicfilePath); voID
AudioManager::preLoadSound(Sound&sound) namespace
CocosDenshion; namespace
cocos2d; sound.soundfilePath=CCfileUtils::sharedfileUtils()->fullPathFromrelativePath(sound.soundfilePath); SimpleAudioEngine::sharedEngine()->preloadEffect(sound.soundfilePath); voID
AudioManager::playMusic(Music&music,87); background-color:inherit; Font-weight:bold">boolloop/*default=true*/) /*先判断是否已经在播放,如果在播放,则直接返回*/
if
(SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()){ return
; } SimpleAudioEngine::sharedEngine()->playBackgroundMusic(music.musicfilePath,loop); voID
AudioManager::playSound(Sound&sound,0); background-color:inherit">/*defaultisfalse*/) sound.soundID=SimpleAudioEngine::sharedEngine()->playEffect(sound.soundfilePath,loop); voID
AudioManager::pauseMusic(Music&music) SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); voID
AudioManager::pauseSound(Sound&sound) SimpleAudioEngine::sharedEngine()->pauseEffect(sound.soundID); voID
AudioManager::stopMusic(Music&music,87); background-color:inherit; Font-weight:bold">boolrelease/*defaultistrue*/) SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(release); voID
AudioManager::stopSound(Sound&sound) SimpleAudioEngine::sharedEngine()->stopEffect(sound.soundID); voID
AudioManager::stopAllSound() SimpleAudioEngine::sharedEngine()->stopAllEffects(); voID
AudioManager::resumeMusic() SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); voID
AudioManager::end() SimpleAudioEngine::sharedEngine()->end(); 注意: 进入游戏后,开始初始化资源调用 /*初始化游戏音效*/
AudioManager::init(); 游戏切换到后台调用: AudioManager::pauseMusic(bgMusic); 游戏重新切换回前台 AudioManager::resumeMusic(); 总结
以上是内存溢出为你收集整理的Cocos2d-X 学习笔记 17 Cocos2dx 下对sqlite3 的简单封装全部内容,希望文章能够帮你解决Cocos2d-X 学习笔记 17 Cocos2dx 下对sqlite3 的简单封装所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
评论列表(0条)