您的位置:首页 > 移动开发 > Cocos引擎

cocos2dx Audio声音引擎

2016-02-13 23:48 387 查看


                      cocos2dx Audio声音引擎


首先包含头文件

#include "SimpleAudioEngine.h"

using namespace CocosDenshion;


播放背景音乐

时间较长一般循环播放

auto audio = SimpleAudioEngine::getInstance();

// set the background music and continuously play it.
audio->playBackgroundMusic("mymusic.mp3", true);

// set the background music and play it just once.
audio->playBackgroundMusic("mymusic.mp3", false);



播放效果音乐

一般为时间比较短的音乐

auto audio = SimpleAudioEngine::getInstance();

// play a sound effect, just once.
audio->playEffect("myEffect.mp3", false, 1.0f, 1.0f, 1.0f);



Pausing, stopping, resuming music and sound effects


暂停播放音乐

auto audio = SimpleAudioEngine::getInstance();

// pause background music.
audio->pauseBackgroundMusic();

// pause a sound effect.
audio->pauseEffect();

// pause all sound effects.
audio->pauseAllEffects();



停止播放音乐

auto audio = SimpleAudioEngine::getInstance();

// stop background music.
audio->stopBackgroundMusic();

// stop a sound effect.
audio->stopEffect();

// stops all running sound effects.
audio->stopAllEffects();


恢复播放音乐
auto audio = SimpleAudioEngine::getInstance();

// resume background music.
audio->resumeBackgroundMusic();

// resume a sound effect.
audio->resumeEffect();

// resume all sound effects.
audio->resumeAllEffects();



预加载音乐

当一个音乐文件比较大时,可以在init()函数中预加载音乐

auto audio = SimpleAudioEngine::getInstance();

audio->preloadBackgroundMusic("myMusic1.mp3");
audio->preloadEffect("myEffect1.mp3");

audio->unloadEffect("myEffect1.mp3");



音量

auto audio = SimpleAudioEngine::getInstance();

// setting the volume specifying value as a float
audio->setEffectsVolume(5.0f);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: