Cocos2d-x:声音控制
推荐:将NSDT场景编辑器加入你的3D工具链
3D工具集:NSDT简石数字孪生
声音控制
开始播放音乐和音效后,你可能需要对它们进行一些控制,比如暂停、停止、恢复。这很容易完成,下面介绍:
暂停
#include "SimpleAudioEngine.h"
using namespace CocosDenshion;
auto audio = SimpleAudioEngine::getInstance();
// pause background music.
audio->pauseBackgroundMusic();
// pause a sound effect.
audio->pauseEffect();
// pause all sound effects.
audio->pauseAllEffects();
停止
#include "SimpleAudioEngine.h"
using namespace CocosDenshion;
auto audio = SimpleAudioEngine::getInstance();
// stop background music.
audio->stopBackgroundMusic();
// stop a sound effect.
audio->stopEffect();
// stops all running sound effects.
audio->stopAllEffects();
恢复
#include "SimpleAudioEngine.h"
using namespace CocosDenshion;
auto audio = SimpleAudioEngine::getInstance();
// resume background music.
audio->resumeBackgroundMusic();
// resume a sound effect.
audio->resumeEffect();
// resume all sound effects.
audio->resumeAllEffects();
由3D建模学习工作室 翻译整理,转载请注明出处!