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

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


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

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