大佬教程收集整理的这篇文章主要介绍了cocos2d中分步实现飞机大战----自己飞机的实现,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
上一节说了背景的滚动,现在开始布置游戏中自己的飞机,为了使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->@H_586_2@moveTo(Director::geTinstance()->getWinSize().width/2,200);
p->setTag(444);
return true;
}
这样在游戏场景中就出现自己的飞机了。
以上是大佬教程为你收集整理的cocos2d中分步实现飞机大战----自己飞机的实现全部内容,希望文章能够帮你解决cocos2d中分步实现飞机大战----自己飞机的实现所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。