cocos2d中分步实现飞机大战----自己飞机的实现
2015-03-08 23:52
225 查看
上一节说了背景的滚动,现在开始布置游戏中自己的飞机,为了使GameScene的代码不至于太多,可以吧自己的飞机进行封装,在GameScene中调用就好。创建Plane:
Plane.h:
#include "cocos2d.h"
USING_NS_CC;
class plane:public
Node{
public:
int hp=100;
int px,py;
CREATE_FUNC(plane);
bool init();
void moveTo(int x,int y);
};
Plane.cpp:
#include "plane.h"
bool
plane::init(){
if (!Node::init()) {
return
false;
}
auto sp=Sprite::create("boss0.png");
sp->setTag(333);
this->addChild(sp);
return
true;
}
void
plane::moveTo(int x,
int y){
this->getChildByTag(333)->setPosition(x,
y);
this->px=x;
this->py=y;
}
在GameScene中调用
首先在开始引用Plane.h
#include "Plane.h"
在init()中实例化:
bool
gameScene::init(){
if (!Layer::init()) {
return
false;
}
plane * p=plane::create();
this->addChild(p);
p->moveTo(Director::getInstance()->getWinSize().width/2,
200);
p->setTag(444);
return
true;
}
这样在游戏场景中就出现自己的飞机了。
Plane.h:
#include "cocos2d.h"
USING_NS_CC;
class plane:public
Node{
public:
int hp=100;
int px,py;
CREATE_FUNC(plane);
bool init();
void moveTo(int x,int y);
};
Plane.cpp:
#include "plane.h"
bool
plane::init(){
if (!Node::init()) {
return
false;
}
auto sp=Sprite::create("boss0.png");
sp->setTag(333);
this->addChild(sp);
return
true;
}
void
plane::moveTo(int x,
int y){
this->getChildByTag(333)->setPosition(x,
y);
this->px=x;
this->py=y;
}
在GameScene中调用
首先在开始引用Plane.h
#include "Plane.h"
在init()中实例化:
bool
gameScene::init(){
if (!Layer::init()) {
return
false;
}
plane * p=plane::create();
this->addChild(p);
p->moveTo(Director::getInstance()->getWinSize().width/2,
200);
p->setTag(444);
return
true;
}
这样在游戏场景中就出现自己的飞机了。
相关文章推荐
- cocos2d中分步实现飞机大战----游戏场景中背景的滚动
- 【cocos2d-x 3.7 飞机大战】 决战南海I (二) 我方飞机的实现
- cocos2d中分步实现飞机大战----场景跳转
- cocos2dx飞机大战Cocos2d-x飞机实现
- 【cocos2d-x 3.7 飞机大战】 决战南海I (二) 我方飞机的实现
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 05.游戏界面 主角飞机的移动
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 06.游戏界面 主角飞机产生子弹
- Cocos2d-x 3.0final 终结者系列教程16-《微信飞机大战》实现
- Cocos2d-x 3.1.1 学习日志5--cocos2d-x3.1.1打飞机的实现
- 项目飞机大战01:主要实现背景的移动,飞机的动画和触控,子弹的生成和发射
- Cocos2d-x 3.0final-《微信飞机大战》实现 -----沈大海
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 04.游戏界面 主角飞机的添加
- [置顶] 【cocos2d-x入门实战】微信飞机大战之四:飞机登场咯
- Cocos2d-x 3.0-《微信飞机大战》实现
- Cocos2d-x 3.2 lua飞机大战开发实例(一)背景地图,飞机,子弹的封装,以及lua中定时器的使用
- Cocos2d-x 3.2 lua飞机大战开发实例(二)敌机类的封装,以及碰撞检测的实现
- [cocos2d-x][游戏开发]通过cocos2d-x实现简易飞机大战 07.游戏界面 敌机的产生与移动
- Cocos2d-x简单游戏<打飞机>代码实现|第一部分:飞机类
- [置顶] 【cocos2d-x入门实战】微信飞机大战之三:飞机要起飞了
- Cocos2d-x3.2 飞机大战类游戏中实现随机出现敌机的方法