首页 > 其他 > 详细

cocos2dx音乐与音效

时间:2014-07-18 09:39:47      阅读:256      评论:0      收藏:0      [点我收藏+]

// 预加载音乐和音效

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音乐与音效

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!