Step-by-step implementation of the aircraft war in cocos2d-Implementation of your own aircraft

Source: Internet
Author: User

Step-by-step implementation of the aircraft war in cocos2d-Implementation of your own aircraft

In the previous section, we talked about the rolling of the background. Now we are setting up our own planes in the game. In order to keep the GameScene code too much, you can encapsulate your own planes and call them in GameScene. Create Plane:

Plane. h:

# Include "cocos2d. h"

USING_NS_CC;

Class plane: publicNode {

Public:

Int hp = 100;

Int px, py;

CREATE_FUNC (plane );

Bool init ();

Void moveTo (int x, int y );

};

Plane. cpp:

# Include "plane. h"

Boolplane: init (){

If (! Node: init ()){

Return false;

}

Auto sp = Sprite: create ("boss0.png ");

Sp-> setTag (333 );

This-> addChild (sp );

Return true;

}

Voidplane: moveTo (int x, int y ){

This-> getChildByTag (333)-> setPosition (x, y );

This-> px = x;

This-> py = y;

}

Call in GameScene

First, start referencing Plane. h.

# Include "Plane. h"

Instantiate in init:

BoolgameScene: init (){

If (! Layer: init ()){

Return false;

}

Plane * p = plane: create ();

This-> addChild (p );

P-> moveTo (Director: getInstance ()-> getWinSize (). width/2,200 );

P-> settags (444 );

Return true;

}

In this way, your plane will appear in the game scene.



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.