Cocos2d-X 学习笔记 17 Cocos2dx 下对sqlite3 的简单封装

前端之家收集整理的这篇文章主要介绍了Cocos2d-X 学习笔记 17 Cocos2dx 下对sqlite3 的简单封装前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. @H_301_2@typedefstruct{
  2. @H_301_2@unsignedintsoundId;
  3. constchar*soundFilePath;
  4. @H_301_2@}Sound;
  5. @H_301_2@
  6. @H_301_2@
  7. @H_301_2@char*musicFilePath;
  8. @H_301_2@}Music;
  9. @H_301_2@/*
  10. @H_301_2@*注意,Andoird下面只支持.ogg
  11. *
  12. */
  13. staticMusicbgMusic=
  14. @H_301_2@{
  15. @H_301_2@"audio/mainbgmusic.ogg"
  16. @H_301_2@};
  17. staticSoundtestSound=
  18. @H_301_2@0,
  19. @H_301_2@"audio/clicksound.ogg"
  20. @H_301_2@};
  21. classAudioManager
  22. public:
  23. /*注意,此方法在进入游戏前调用*/
  24. staticvoidinit();
  25. /*预加载*/
  26. voidpreLoadBgMusic(Music&music);
  27. voidpreLoadSound(Sound&sound);
  28. /*播放*/
  29. voidplayMusic(Music&music,boolloop=true);
  30. voidplaySound(Sound&sound,153); background-color:inherit; font-weight:bold">false);
  31. /*暂停*/
  32. voidpauseMusic(Music&music);
  33. voidpauseSound(Sound&sound);
  34. /*停止*/
  35. voidstopMusic(Music&music,87); background-color:inherit; font-weight:bold">boolrelease=voidstopSound(Sound&sound);
  36. voidstopAllSound();
  37. /*恢复*/
  38. voidresumeMusic();
  39. /*全部结束*/
  40. voidend();
  41. @H_301_2@</pre><br>
  42. @H_301_2@<pre></pre>
  43. @H_301_2@<br>
  44. @H_301_2@<prename="code"class="cpp"><prename="code"class="cpp">voidAudioManager::init()
  45. @H_301_2@{
  46. /*例子*/
  47. @H_301_2@preLoadBgMusic(bgMusic);
  48. @H_301_2@preLoadSound(testSound);
  49. @H_301_2@}
  50. /*********************************************************
  51. 一些方法的封装
  52. *********************************************************/
  53. voidAudioManager::preLoadBgMusic(Music&music)
  54. usingnamespaceCocosDenshion;
  55. namespacecocos2d;
  56. @H_301_2@music.musicFilePath=CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(music.musicFilePath);
  57. @H_301_2@CCLOG(music.musicFilePath);
  58. @H_301_2@SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(music.musicFilePath);
  59. voidAudioManager::preLoadSound(Sound&sound)
  60. namespaceCocosDenshion;
  61. namespacecocos2d;
  62. @H_301_2@sound.soundFilePath=CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(sound.soundFilePath);
  63. @H_301_2@SimpleAudioEngine::sharedEngine()->preloadEffect(sound.soundFilePath);
  64. voidAudioManager::playMusic(Music&music,87); background-color:inherit; font-weight:bold">boolloop/*default=true*/)
  65. /*先判断是否已经在播放,如果在播放,则直接返回*/
  66. if(SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()){
  67. return;
  68. @H_301_2@}
  69. @H_301_2@SimpleAudioEngine::sharedEngine()->playBackgroundMusic(music.musicFilePath,loop);
  70. voidAudioManager::playSound(Sound&sound,0); background-color:inherit">/*defaultisfalse*/)
  71. @H_301_2@sound.soundId=SimpleAudioEngine::sharedEngine()->playEffect(sound.soundFilePath,loop);
  72. voidAudioManager::pauseMusic(Music&music)
  73. @H_301_2@SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
  74. voidAudioManager::pauseSound(Sound&sound)
  75. @H_301_2@SimpleAudioEngine::sharedEngine()->pauseEffect(sound.soundId);
  76. voidAudioManager::stopMusic(Music&music,87); background-color:inherit; font-weight:bold">boolrelease/*defaultistrue*/)
  77. @H_301_2@SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(release);
  78. voidAudioManager::stopSound(Sound&sound)
  79. @H_301_2@SimpleAudioEngine::sharedEngine()->stopEffect(sound.soundId);
  80. voidAudioManager::stopAllSound()
  81. @H_301_2@SimpleAudioEngine::sharedEngine()->stopAllEffects();
  82. voidAudioManager::resumeMusic()
  83. @H_301_2@SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
  84. voidAudioManager::end()
  85. @H_301_2@SimpleAudioEngine::sharedEngine()->end();
  86. 注意:
  87. @H_301_2@ 进入游戏后,开始初始化资源调用
  88. /*初始化游戏音效*/
  89. @H_301_2@AudioManager::init();


  90. @H_301_2@游戏切换到后台调用:
  91. @H_301_2@AudioManager::pauseMusic(bgMusic);
  92. @H_301_2@游戏重新切换回前台
  93. @H_301_2@AudioManager::resumeMusic();
原文链接:https://www.f2er.com/cocos2dx/346716.html

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