http://shahdza.blog.51cto.com/2410787/1545820/
|
背景音乐 | 音效 |
Win32 | MP3、MID、WAV | MID、WAV |
Android | OGG | |
IOS | MP3、CAF | CAF |
1
2
3
4
|
//通过SimpleAudioEngine::sharedEngine()获得
static
SimpleAudioEngine*sharedEngine();
4、背景音乐的函数
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void
preloadBackgroundMusic(
'音乐路径constchar*'
);
//预加载
stopBackgroundMusic(
bReleaseData=
//停止,是否释放音乐资源
pauseBackgroundMusic();
//暂停
resumeBackgroundMusic();
//恢复
rewindBackgroundMusic();
//重播
//返回是否将要播放背景音乐
willPlayBackgroundMusic();
//返回是否正在播放背景音乐
//注意:暂停也算正在播放,只有停止了才算未播放。
isBackgroundMusicPlaying();
//设置音量,取值范围0~1.0
//查看了内部源码,发现音量的设置没有实现,即音量永远是1.0
float
getBackgroundMusicVolume();
setBackgroundMusicVolume(
volume);
5、音效的函数
21
preloadEffect(
unsigned
int
playEffect(
//播放,返回该音效的ID。是否循环
stopEffect(unsigned
nSoundId);
//停止指定ID的音效
stopAllEffects();
//停止所有音效
pauseEffect(unsigned
//暂停指定ID的音效
pauseAllEffects();
//暂停所有音效
resumeEffect(unsigned
//恢复指定ID的音效
resumeAllEffects();
//恢复所有音效
unloadEffect(
const
char
*pszFilePath);
//卸载音效资源
getEffectsVolume();
setEffectsVolume(
6、关于预加载
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
/**
* 根据平台选择音乐音效的格式
*/
//音效文件
//Android平台只支持OGG的音效格式
#if(CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID)
#defineEFFECT_FILE"music/effect2.ogg"
#elif(CC_TARGET_PLATFORM==CC_PLATFORM_MARMALADE)
#defineEFFECT_FILE"music/effect1.raw"
#else
#defineEFFECT_FILE"music/effect1.wav"
#endif
//音乐文件
#if(CC_TARGET_PLATFORM==CC_PLATFORM_WIN32)
#defineMUSIC_FILE"music/music.mid"
#elif(CC_TARGET_PLATFORM==CC_PLATFORM_BLACKBerry||CC_TARGET_PLATFORM==CC_PLATFORM_LINUX)
#defineMUSIC_FILE"music/background.ogg"
#elif(CC_TARGET_PLATFORM==CC_PLATFORM_WP8)
#defineMUSIC_FILE"music/background.wav"
#else
#defineMUSIC_FILE"music/background.mp3"
#endif
/**
* 预加载音乐音效
*/
//加载背景音乐
SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(MUSIC_FILE);
//加载音效
SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(EFFECT_FILE);
7、关于音量调节
19
SimpleAudioEngine::getBackgroundMusicVolume()
{
return
1.0;
}
SimpleAudioEngine::setBackgroundMusicVolume(
volume)
{
}
SimpleAudioEngine::getEffectsVolume()
{
1.0;
}
SimpleAudioEngine::setEffectsVolume(
volume)
{
}
8、使用技巧
3
SimpleAudioEngine::sharedEngine()->end()
//创建控制音乐音效的菜单按钮
std::stringtestItems[]={
"playbackgroundmusic"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"stopbackgroundmusic"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"pausebackgroundmusic"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"resumebackgroundmusic"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"rewindbackgroundmusic"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"isbackgroundmusicplaying"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"playeffect"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"playeffectrepeatly"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"stopeffect"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"pauseeffect"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"resumeeffect"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"pausealleffects"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"resumealleffects"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"stopalleffects"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"unloadeffect"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"addbackgroundmusicvolume"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"subbackgroundmusicvolume"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"addeffectsvolume"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,
"subeffectsvolume"
};
//创建菜单
pMenu->setContentSize(CCSizeMake(480,1000));
for
(
i=0;i<19;++i)
{
cclabelTTF*label=cclabelTTF::create(testItems[i].c_str(),
"Arial"
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,24);
CcmenuItemLabel*pMenuItem=CcmenuItemLabel::create(label,
this
ottom:auto!important; float:none!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,menu_selector(HelloWorld::menuCallback));
pMenuItem->setPosition(ccp(mysize.width/2,1000-(i+1)*50));
pMenu->addChild(pMenuItem,i);
}
//将菜单作为容器,放入滚动视图中
CCScrollView*scrollView=CCScrollView::create(CCSizeMake(480,320),pMenu);
scrollView->setDirection(kCCScrollViewDirectionVertical);
scrollView->setPosition(CCPointZero);
pMenu->setPosition(ccp(0,320-1000));
->addChild(scrollView);
HelloWorld::menuCallback(CCObject*sender)
{
idx=((CcmenuItem*)sender)->getTag();
switch
(idx)
{
//音乐控制
case
0:SimpleAudioEngine::sharedEngine()->playBackgroundMusic(MUSIC_FILE,153)!important; background:none!important">true
);
break
;
//播放音乐,循环
1:SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
//停止音乐
2:SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
//暂停音乐
3:SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
//恢复音乐
4:SimpleAudioEngine::sharedEngine()->rewindBackgroundMusic();
//重播音乐
5:
{
}
else
{
"backgroundmusicisnotplaying"
);
}
;
//音效控制
7:m_soundID=SimpleAudioEngine::sharedEngine()->playEffect(EFFECT_FILE,0)!important; background:none!important">//播放音效,循环
8:SimpleAudioEngine::sharedEngine()->stopEffect(m_soundID);
//停止指定ID的音效
9:SimpleAudioEngine::sharedEngine()->pauseEffect(m_soundID);
//暂停指定ID的音效
10:SimpleAudioEngine::sharedEngine()->resumeEffect(m_soundID);
//恢复指定ID的音效
11:SimpleAudioEngine::sharedEngine()->pauseAllEffects();
//暂停所有音效
12:SimpleAudioEngine::sharedEngine()->resumeAllEffects();
//恢复所有音效
13:SimpleAudioEngine::sharedEngine()->stopAllEffects();
//停止所有音效
14:SimpleAudioEngine::sharedEngine()->unloadEffect(EFFECT_FILE);
//卸载音效
//音量控制
15:
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume()+0.1f);
;
16:
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume()-0.1f);
;
17:
SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume()+0.1f);
;
18:
SimpleAudioEngine::sharedEngine()->setEffectsVolume(SimpleAudioEngine::sharedEngine()->getEffectsVolume()-0.1f);
;
}
}
6、运行结果
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。
相关推荐
本文实践自 RayWenderlich、Ali Hafizji 的文章《How To Create Dynamic Textures with CCRenderTexture in Cocos2D 2.X》,文中使用Cocos2D,我在这里使用Cocos2D-x 2.1.4进行学习和移植。在这篇文章,将会学习到如何创建实时纹理、如何用Gimp创建无缝拼接纹
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@163.com微信公众号:HopToad 欢迎转载,转载标注出处:http://blog.csdn.netotbaron/article/details/424343991. 软件准备 下载地址:http://cn.cocos2d-x.org/download 2. 简介2.1 引用C
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从Cocos2D-x官网上下载,进入网页http://www.cocos2d-x.org/download,点击Cocos2d-x以下的Download v3.0,保存到自定义的文件夹2:从python官网上下载。进入网页https://www.python.org/downloads/,我当前下载的是3.4.0(当前最新
Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发引擎,易学易用,支持多种智能移动平台。官网地址:http://cocos2d-x.org/当前版本:2.0 有很多的学习资料,在这里我只做为自己的笔记记录下来,错误之处还请指出。在VisualStudio2008平台的编译:1.下载当前稳
1. 来源 QuickV3sample项目中的2048样例游戏,以及最近《最强大脑》娱乐节目。将2048改造成一款挑战玩家对数字记忆的小游戏。邮箱:appdevzw@163.com微信公众号:HopToadAPK下载地址:http://download.csdn.net/detailotbaron/8446223源码下载地址:http://download.csdn.net/
Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试以QtCreatorIDE来进行CMake构建。Cocos2d-x3.X地址:https://github.com/cocos2d/cocos2d-x1.打开QtCreator,菜单栏→"打开文件或项目...",打开cocos2d-x目录下的CMakeLists.txt文件;2.弹出CMake向导,如下图所示:设置
下载地址:链接:https://pan.baidu.com/s/1IkQsMU6NoERAAQLcCUMcXQ提取码:p1pb下载完成后,解压进入build目录使用vs2013打开工程设置平台工具集,打开设置界面设置: 点击开始编译等待编译结束编译成功在build文件下会出现一个新文件夹Debug.win32,里面就是编译
分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net前言上次用象棋演示了cocos2dx的基本用法,但是对cocos2dx并没有作深入的讨论,这次以超级马里奥的源代码为线索,我们一起来学习超级马里奥的实
1. 圆形音量button事实上作者的本意应该是叫做“电位计button”。可是我觉得它和我们的圆形音量button非常像,所以就这么叫它吧~先看效果:好了,不多解释,本篇到此为止。(旁白: 噗。就这样结束了?)啊才怪~我们来看看代码:[cpp] viewplaincopyprint?CCContro
原文链接:http://www.cnblogs.com/physwf/archive/2013/04/26/3043912.html为了进一步深入学习贯彻Cocos2d,我们将自己写一个场景类,但我们不会走的太远,凡是都要循序渐进,哪怕只前进一点点,那也至少是前进了,总比贪多嚼不烂一头雾水的好。在上一节中我们建