The previous section said the background of the scroll, and now began to decorate the game of their own aircraft, in order to make the Gamescene code is not too much, you can have their own aircraft encapsulation, call in the Gamescene is good. Create plane:
Plane.h:
#include "Cocos2d.h"
USING_NS_CC;
Class plane:publicNode{
Public:
int hp=;
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;
}
Called in Gamescene
Start by referencing Plane.h first
#include "Plane.h"
Instantiate in Init ():
BOOL gamescene:: Init () {
if (! Layer::init()) {
return false;
}
plane * p=plane::create();
This,addChild(p);
p->moveTo(Director::getinstance(), Getwinsize(). width / 2 , $ );
P->settag(444);
return true;
}
In this way, you will have your own plane in the game scene.
Cocos2d The realization of airplane war----own plane