第一部分:Cocos2d-x简单游戏<打飞机>代码实现|第一部分:飞机类
第二部分:Cocos2d-x简单游戏<打飞机>代码实现|第二部分:子弹类
第三部分:Cocos2d-x简单游戏<打飞机>代码实现|第三部分:引导层
#ifndef __ShootPlane__InstroLayer__
#define __ShootPlane__InstroLayer__
#include <iostream>
#include "commonHeader.h"
//引导层
class IntroLayer:publicCCLayer {
private:
//设置背景
CCSprite *background1;
CCSprite *backgroudd2;
//自适应背景
int adjustmentBg;
//更新
void update(float delate);
//加载背景
void loadBackground();
//背景轮换
void backgroundScrollRelpace();
public:
//构造函数及析构函数
IntroLayer();
~IntroLayer();
//创建场景
CREATE_FUNC(IntroLayer);
virtual bool init();//初始化场景
//
SCENE_FUNC(IntroLayer);
virtual void onEnter();//系统函数
};
#endif /* defined(__ShootPlane__InstroLayer__) */
#include "InstroLayer.h"
#include "HelloWorldScene.h"
IntroLayer::IntroLayer(){
}
IntroLayer ::~IntroLayer(){
}
//加载背景
voidIntroLayer ::loadBackground(){
//设置背景1属性并添加到视图上
this->background1 =CCSprite::createWithSpriteFrameName("background_2.png");
this->background1->setAnchorPoint(ccp(0.5,0));
this->background1->setPosition(ccp(160,adjustmentBg));
this->addChild(background1,0);
//设置背景2
this->backgroudd2 =CCSprite::createWithSpriteFrameName("background_2.png");
this->backgroudd2->setAnchorPoint(ccp(0.5,0));
this->backgroudd2->setPosition(ccp(160,568 + adjustmentBg));
this->addChild(backgroudd2,0);
}
//背景轮换滚动
voidIntroLayer::backgroundScrollRelpace(){
adjustmentBg--;
if (adjustmentBg <=0) {
adjustmentBg = 568;
}
background1->setPosition(ccp(160,adjustmentBg));
backgroudd2->setPosition(ccp(160,adjustmentBg - 568));
}
//更新
voidIntroLayer::update(float delate){
//调用背景更换
this->backgroundScrollRelpace();
}
boolIntroLayer::init(){
kCCLAYER_IS_INIT;
//加载贴图缓存
CCTexture2D *texture =CCTextureCache::sharedTextureCache()->textureForKey("gameArts.png");
//加载批量帧
CCSpriteBatchNode *spriteBatch =CCSpriteBatchNode::createWithTexture(texture);
this->addChild(spriteBatch);
//调用加载视图方法
this->loadBackground();
this->scheduleUpdate();//调用定时器更新
return true;
}
voidIntroLayer::onEnter(){
//实例化helloWorld场景
CCScene *pScene = HelloWorld::scene();
//创建切换场景模式
CCTransitionFade *transitionScene =CCTransitionFade::create(1.0,pScene,ccWHITE);
//切换场景
CCDirector::sharedDirector()->replaceScene(transitionScene);
}