第一部分:Cocos2d-x简单游戏<打飞机>代码实现|第一部分:飞机类
第二部分:Cocos2d-x简单游戏<打飞机>代码实现|第二部分:子弹类
第三部分:Cocos2d-x简单游戏<打飞机>代码实现|第三部分:引导层
#ifndef __ShootPlane__CCPlane__
#define __ShootPlane__CCPlane__
#include <iostream>
#include "commonHeader.h"
//创建飞机类
class CCPlane:publiccocos2d:: CCSprite {
public:
//声明一个飞机类型、飞机速度、飞机编号...
int planeType, hp, speed,__id;
public:
CCPlane();//构造函数
~CCPlane();//析构函数
//创建缓存精灵帧
static CCPlane *createWithSpriteFrameName(constchar *pszSpriteFrameName);
};
#endif /* defined(__ShootPlane__CCPlane__) */
#include "CCPlane.h"
//实现析构函数和构造函数
CCPlane::CCPlane():planeType(0),hp(0),speed(0),__id(0){
}
//实现析构函数
CCPlane::~CCPlane(){
CCLOG("%s",__FUNCTION__);
}
//初始化精灵帧
CCPlane *CCPlane::createWithSpriteFrameName(constchar *pszSpriteFrameName){
//实例化一个精灵对象
CCPlane *pSprite = new CCPlane;
//判断精灵是否存在,并初始化精灵帧
if (pSprite && pSprite->initWithSpriteFrameName(pszSpriteFrameName)) {
pSprite->autorelease();
return pSprite;
}
//安全删除
CC_SAFE_DELETE(pSprite);
return NULL;
}