欢迎来到天天文库
浏览记录
ID:17877532
大小:164.50 KB
页数:7页
时间:2018-09-07
《二、创建游戏窗口界面动画》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、二、创建游戏窗口界面动画1.打开项目,添加游戏界面类InGameLayer,同样加入头文件和域名空间,具体内容上次试验指导有。2.编写每个类必要的初始化函数#pragmaonce#include"c:cocos2d-x-2.2.1cocos2dxlayers_scenes_transitions_nodescclayer.h"#include"cocos2d.h"usingnamespacecocos2d;classInGameLayer:publicCCLayer{public:InGameLayer(void);~InGameLayer(void)
2、;public:CREATE_FUNC(InGameLayer);virtualboolinit();//场景初始化//there'sno'id'incpp,sowerecommendreturningtheclassinstancepointerstaticcocos2d::CCScene*CreateScene();//场景对象函数};CCScene*InGameLayer::CreateScene(){//'scene'isanautoreleaseobjectCCScene*scene=CCScene::create();//'layer'isanau
3、toreleaseobjectInGameLayer*layer=InGameLayer::create();//addlayerasachildtoscenescene->addChild(layer);//returnthescenereturnscene;}boolInGameLayer::init(){boolb1=CCLayer::init();Winsize=CCDirector::sharedDirector()->getVisibleSize();returnb1;}1.添加战斗场景背景类GameObject,用于存放背景滚动效果#pragma
4、once#include"c:cocos2d-x-2.2.1cocos2dxlayers_scenes_transitions_nodescclayer.h"#include"cocos2d.h"usingnamespacecocos2d;classGameObject:publicCCLayer{public:GameObject(void);~GameObject(void);public:CREATE_FUNC(GameObject);virtualboolinit();voidmove();//设置背景移动函数//there'sno'id'in
5、cpp,sowerecommendreturningtheclassinstancepointerprivate:cocos2d::CCSprite*back1;//第一张背景图cocos2d::CCSprite*back2;//第二张背景图floatvy;//背景移动速度};在GameObject.cpp下实现该实现的函数首先对3个变量在构造函数进行初始化GameObject::GameObject(void){back1=NULL;back2=NULL;vy=5.5f;}//实现初始化和移动函数boolGameObject::init(){boolb1=C
6、CLayer::init();back1=CCSprite::create("bg_02.png");//载入第一张背景图this->addChild(back1);back1->setAnchorPoint(ccp(0,0));//设置对应的坐标back1->setPosition(ccp(0,0));//设置位置back2=CCSprite::create("bg_01.png");//载入第二张背景图this->addChild(back2);back2->setAnchorPoint(ccp(0,0));//设置对应的坐标back2->setPosit
7、ion(ccp(0,back1->getPositionY()+back1->getContentSize().height-2));//将图片放在图片1上的位置上returnb1;}voidGameObject::move(){//计算移动速度floatoneNextPos=back1->getPositionY()-vy;floattwoNextPos=back2->getPositionY()-vy;//设置图片跑起来back1->setPositionY(oneNextPos);//设置图片1的Y坐标back2->setPositionY(twoNex
8、tPos);//设置图片2的Y坐标if
此文档下载收益归作者所有