cocos2dx——实现儿童节贺卡01
2015-06-02 00:26
337 查看
有些时间没有用到cocos了,净忙着复习,屌丝过个儿童节貌似更屌丝,还是敲代码吧,看着别人在朋友圈里发照片,我的照片呢?算了,给外甥做个贺卡,也当复习复习cocos了!
先说一说贺卡大体的效果:
1.进入欢迎界面,实现淡入淡出的效果;
2.实现一个幻灯片播放,每张切换都用淡入淡出效果,同时添加粒子特效;
3.幻灯片播放之后,进入祝贺界面:几个字体通过各种动作实现一些效果;
4.添加背景音乐的播放(在windows上不能用mp3,这让我纠结了半天,谁让之前一直不加音乐呢)
下面先实现以下欢迎界面吧,创建项目,直接使用helloworld界面,在这里helloworldScene还是好名字
接下来实现文件
先说一说贺卡大体的效果:
1.进入欢迎界面,实现淡入淡出的效果;
2.实现一个幻灯片播放,每张切换都用淡入淡出效果,同时添加粒子特效;
3.幻灯片播放之后,进入祝贺界面:几个字体通过各种动作实现一些效果;
4.添加背景音乐的播放(在windows上不能用mp3,这让我纠结了半天,谁让之前一直不加音乐呢)
下面先实现以下欢迎界面吧,创建项目,直接使用helloworld界面,在这里helloworldScene还是好名字
#ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" class HelloWorld : public cocos2d::Layer { public: // there's no 'id' in cpp, so we recommend returning the class instance pointer static cocos2d::Scene* createScene(); // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone virtual bool init(); // implement the "static create()" method manually CREATE_FUNC(HelloWorld); void replaceSceneCallback(); }; #endif // __HELLOWORLD_SCENE_H__
接下来实现文件
#include "HelloWorldScene.h" #include "ThreeScene.h" #include "SimpleAudioEngine.h" USING_NS_CC; using namespace CocosDenshion; Scene* HelloWorld::createScene() { // 'scene' is an autorelease object auto scene = Scene::create(); // 'layer' is an autorelease object auto layer = HelloWorld::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene; } // on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); auto bg = Sprite::create("bg.png"); bg->setScale(0.4); this->addChild(bg); bg->setPosition(visibleSize.width / 2, visibleSize.height / 2); bg->setOpacity(50); //设置透明度 auto fadein = FadeIn::create(2.0f); //淡入 auto fadeout = FadeOut::create(2.0f);//淡出 auto callfunc = CallFunc::create(CC_CALLBACK_0(HelloWorld::replaceSceneCallback, this));//回调,动作完成后切换另一个场景 auto sequence = Sequence::create(fadein, fadeout, callfunc,NULL); bg->runAction(sequence); return true; } void HelloWorld::replaceSceneCallback() { Director::getInstance()->replaceScene(TransitionFade::create(1.2f, ThreeScene::createScene()));//淡入切换场景,可以使用多种效果 }
相关文章推荐
- Cocos2d-x 详解坐标系统
- quick-cocos2d 之动态更新
- cocos2d-x播放视频(VideoPlayer)小记
- cocos2dx Armature动画
- Cocos2d-x CCProgressTimer
- 使用Tiled制作地图
- cocos2dx3.4 BOX2D debugdraw
- iOS和android游戏纹理优化和内存优化(cocos2d-x)
- Cocos2D-X下,iOS设备显示多行文字显示不全的问题
- cocos2d 内存管理机制
- 【木头Cocos2d-x 016】控件篇(第01章) 我最爱的九妹和按钮事件
- 我的Cocos2d-x学习笔记(十五)CCControlSlider、CCControlSwitch、CCScale9Sprite、CCControlButton
- cocos2d-x-3.4 无法打开包含文件extensions/ExtensionExport.h
- Cocos2d-x的学习之旅(二)HelloWorld
- cocos2dx常用工具集
- 从cocostudio获取控件,添加回调函数
- Cocos2d-x3.2 定时器的使用
- cocos v2.2.6&cocos2d-x-3.6实练
- Cocos2d-x动作CCAction
- 如何在cocos2d-x中加入一个UIView