声音控制

开始播放音乐和音效后,你可能需要对它们进行一些控制,比如暂停、停止、恢复。这很容易完成,下面介绍:

暂停

C++

  1. #include "SimpleAudioEngine.h"
  2. using namespace CocosDenshion;
  3. auto audio = SimpleAudioEngine::getInstance();
  4. // pause background music.
  5. audio->pauseBackgroundMusic();
  6. // pause a sound effect.
  7. audio->pauseEffect();
  8. // pause all sound effects.
  9. audio->pauseAllEffects();

停止

C++

  1. #include "SimpleAudioEngine.h"
  2. using namespace CocosDenshion;
  3. auto audio = SimpleAudioEngine::getInstance();
  4. // stop background music.
  5. audio->stopBackgroundMusic();
  6. // stop a sound effect.
  7. audio->stopEffect();
  8. // stops all running sound effects.
  9. audio->stopAllEffects();

恢复

C++

  1. #include "SimpleAudioEngine.h"
  2. using namespace CocosDenshion;
  3. auto audio = SimpleAudioEngine::getInstance();
  4. // resume background music.
  5. audio->resumeBackgroundMusic();
  6. // resume a sound effect.
  7. audio->resumeEffect();
  8. // resume all sound effects.
  9. audio->resumeAllEffects();

原文: http://docs.cocos.com/cocos2d-x/manual/zh/audio/operations.html