码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2dx音乐与音效

时间:2014-07-18 16:09:28      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:style   os   io   cti   re   c   

// 预加载音乐和音效

SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile("fashu1.wav","fashu1.wav"));

SimpleAudioEngine::sharedEngine()->preloadEffect(CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile("fashu1.wav","fashu1.wav"));


// 设置默认音量
SimpleAudioEngine::sharedEngine()->setEffectsVolume(0.5);
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.5);

 

// 播放背景音乐

SimpleAudioEngine::sharedEngine()->playBackgroundMusic(CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile("fashu1.wav","fashu1.wav")); 

// 停止背景音乐

SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();

// 暂停背景音乐

SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();

// 继续播放背景音乐

SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();

// 后退背景音乐

SimpleAudioEngine::sharedEngine()->rewindBackgroundMusic();

// 背景音乐是否正在播放

if (SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())

{ CCLOG("正在播放"); }

else CCLOG("没在播放");

// 播放音效,并且得到此音效的ID

SimpleAudioEngine::sharedEngine()->playEffect(CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile("fashu1.wav","fashu1.wav"));

// 重复播放音效

SimpleAudioEngine::sharedEngine()->playEffect(std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(MUSIC_FILE)).c_str(), true);

// 停止播放音效

SimpleAudioEngine::sharedEngine()->stopEffect(effectId);

// 释放音效

SimpleAudioEngine::sharedEngine()->unloadEffect (std::string(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(MUSIC_FILE)).c_str() );

// 增加背景音乐音量

SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume()+0.1f);

// 减少背景音乐音量

SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume()-0.1f);

// 增加背景音效音量

SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume()+0.1f);

// 减少背景音效音量

SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume()-0.1f);

// 暂停音效

SimpleAudioEngine::sharedEngine()->pauseEffect(effectId);

// 继续 播放音效

SimpleAudioEngine::sharedEngine()->resumeEffect(effectId);

cocos2dx音乐与音效,布布扣,bubuko.com

cocos2dx音乐与音效

标签:style   os   io   cti   re   c   

原文地址:http://www.cnblogs.com/ADaii/p/3851924.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!