首页 > 其他 > 详细

cocos2d中分步实现飞机大战----自己飞机的实现

时间:2015-03-09 09:25:32      阅读:392      评论:0      收藏:0      [点我收藏+]

上一节说了背景的滚动,现在开始布置游戏中自己的飞机,为了使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;

}

这样在游戏场景中就出现自己的飞机了。



cocos2d中分步实现飞机大战----自己飞机的实现

原文:http://blog.csdn.net/u012734194/article/details/44142497

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!