第1天的地址:
http://blog.csdn.net/xingxiliang/article/details/18557631
书接上回:今天我们让我们的游戏加点背景音乐,而且可以切换场景。
avi版本可以方便的在手机,pc上查看。下载地址:http://pan.baidu.com/s/1ELk78
1. 播放背景音乐,实时音乐
#include "SimpleAudioEngine.h" CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("pew-pew-lei.wav"); // 实时音乐 CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("background-music-aac.wav", true);// 循环播放背景音
2. 创建一个自己的场景
可以实现场景之间的切换,可以实现延时动作。
// GameOverLayer.h #include "cocos2d.h" class GameOverLayer : public cocos2d::CCLayerColor { public: cocos2d::CCLabelTTF* _label; bool init(); ~GameOverLayer(); static cocos2d::CCScene* scene(); CREATE_FUNC(GameOverLayer); void returnToGame(cocos2d::CCNode*); // CCLabelTTF::create() HelloWorld::create() }; // GameOverLayer.cpp #include "GameOverLayer.h" #include "HelloWorldScene.h" USING_NS_CC; bool GameOverLayer::init() { if (CCLayerColor::initWithColor(ccc4(0, 255, 0, 255))){ _label = CCLabelTTF::create("word", "Artial", 40); CCSize size = CCDirector::sharedDirector()->getVisibleSize(); _label->setPosition(ccp(size.width / 2, size.height / 2)); this->addChild(_label); _label->retain(); //保证_label 跟类对象有同样的生命周期 CCDelayTime* delay = CCDelayTime::create(5); // 执行一个延时动作 CCCallFuncN* returnToGame = CCCallFuncN::create(this, callfuncN_selector(GameOverLayer::returnToGame)); this->runAction(CCSequence::create(delay, returnToGame, NULL)); return true; } return false; } void GameOverLayer::returnToGame(CCNode*) { CCDirector::sharedDirector()->replaceScene(HelloWorld::scene()); // 场景之间切换 } GameOverLayer::~GameOverLayer() { if (_label){ _label->release(); } } cocos2d::CCScene* GameOverLayer::scene() { CCScene* scene = CCScene::create(); GameOverLayer* layer = GameOverLayer::create(); layer->setTag(100); scene->addChild(layer); return scene; }
上传到了优酷
http://v.youku.com/v_show/id_XNjY0MjEzNzI0.html 第1课
http://v.youku.com/v_show/id_XNjY0MjMzMzYw.html 第2课
http://v.youku.com/v_show/id_XNjY0MjU1OTcy.html 第3课
http://v.youku.com/v_show/id_XNjY0MzQxMDE2.html 第4课
http://v.youku.com/v_show/id_XNjY1MTI3NjYw.html 第5课
http://v.youku.com/v_show/id_XNjY1MTI5ODQw.html 第6课
高清还请从百度网盘下载。
转载请注明出处:http://blog.csdn.net/xingxiliang/article/details/18681575