@H_403_0@
@H_403_0@接着看教程:播放音乐与音效,然后想实现一个播放,暂停,停止的小功能,就附加看了一下Menu的一些知识,又回顾了一下坐标系 @H_403_0@音乐和音效的播放主要使用的SimpleAudioEngine,目前看3.x里面SimpleAudioEngine的注释没有说depart,所以应该和2.x是一直的。 @H_403_0@1、先导入头文件和命名空间
#include <SimpleAudioEngine.h> using namespace CocosDenshion;
2、SimpleAudioEngine::getInstance()初始化AudioEngine,在Scene的init中调用
SimpleAudioEngine::getInstance()->preloadBackgroundMusic(BG_MUSIC); SimpleAudioEngine::getInstance()->preloadEffect(DOG_WANGWANG);
预加载音频文件 @H_403_0@3、然后在相应的事件处理中,就可以调用相关方法,比如:
SimpleAudioEngine::getInstance()->playBackgroundMusic(BG_MUSIC,true); dog_wangwang = SimpleAudioEngine::getInstance()->playEffect(DOG_WANGWANG); SimpleAudioEngine::getInstance()->resumeBackgroundMusic(); SimpleAudioEngine::getInstance()->resumeEffect(dog_wangwang); if (SimpleAudioEngine::getInstance()->isBackgroundMusicPlaying()){ SimpleAudioEngine::getInstance()->pauseBackgroundMusic(); } if (dog_wangwang > 0){ SimpleAudioEngine::getInstance()->pauseEffect(dog_wangwang); } SimpleAudioEngine::getInstance()->stopBackgroundMusic(true); SimpleAudioEngine::getInstance()->stopAllEffects();还有一些方法,可以查看定义。 @H_403_0@
@H_403_0@Menu继承关系如图:
@H_403_0@
@H_403_0@简单使用
auto playBgMusic = MenuItemFont::create("Paly BgMusic",CC_CALLBACK_1(HelloWorld::menuPlayBgMusicCallback,this)); playBgMusic->setPosition(Vec2(visibleSize.width / 5,visibleSize.height / 6)); // create menu,it's an autorelease object auto menu = Menu::create(closeItem,playBgMusic,playEffect,pause,resume,stop,NULL); menu->setPosition(Vec2::ZERO); this->addChild(menu,1); void HelloWorld::menuPlayBgMusicCallback(Ref* pSender){ SimpleAudioEngine::getInstance()->playBackgroundMusic(BG_MUSIC,true); }
更多的可以去下面的资源地址里看一下
@H_403_0@
@H_403_0@相关资源地址: @H_403_0@教程:http://blog.csdn.net/u012945598/article/details/16992389 @H_403_0@Menu:http://www.tuicool.com/articles/immUVn http://my.oschina.net/Jacedy/blog/301709 @H_403_0@坐标系:http://cn.cocos2d-x.org/article/index?type=cocos2d-x&url=/doc/cocos-docs-master/manual/framework/native/v3/coordinate-system/zh.md @H_403_0@
@H_403_0@demo地址:http://download.csdn.net/detail/lsmfeixiang/8309609 原文链接:https://www.f2er.com/cocos2dx/345228.html