Cocos2d The realization of airplane war----own plane

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.