cocos2d-x中的音效管理

加入头文件

 

#include "SimpleAudioEngine.h"
using namespace CocosDenshion;

 

预加载背景音乐和音效 

 

void AudioManager::addAudio()
{
	//加载北京音乐
	SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(music_bg1);
	SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(music_bg2);
	SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(music_bg3);

	//加载音效
	SimpleAudioEngine::sharedEngine()->preloadEffect(audio_cuowu);
	SimpleAudioEngine::sharedEngine()->preloadEffect(audio_daojishi);
	SimpleAudioEngine::sharedEngine()->preloadEffect(audio_lose);
	SimpleAudioEngine::sharedEngine()->preloadEffect(audio_shiyongDJ);
	SimpleAudioEngine::sharedEngine()->preloadEffect(audio_win);
	SimpleAudioEngine::sharedEngine()->preloadEffect(audio_zhengque);

	//设置音量
	SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume()+10.8f);
	SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume()+10.8f);


}

 

播放音乐

 

SimpleAudioEngine::sharedEngine()->playBackgroundMusic(music_bg1,true);
 

你可能感兴趣的:(cocos2d-x)