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->moveTo(Director::getInstance()->getWinSize().width/2,200); p->setTag(444); return true; } 这样在游戏场景中就出现自己的飞机了。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |