一、层的概念
我们从Cocosd2x框架中可以看出,它分为导演-->场景--->层-->精灵,并且为树状结构;一个导演可以包含多个场景、一个场景可以包含多个层。那当然,一个层可以包含多个精灵,他们相当于一个容器,子容器中设置我们要显示的东西。
二、cclayerColor类
#ifndef __T06cclayers_H__ #define __T06cclayers_H__ #include "cocos2d.h" #include "f:\cocos2dx\cocos2d-x-2.2.6\cocos2dx\layers_scenes_transitions_nodes\cclayer.h" USING_NS_CC; class T06cclayers : public cclayer { public: T06cclayers(void); ~T06cclayers(void); static CCScene* scene(); CREATE_FUNC(T06cclayers); bool init(); }; #endif
<pre name="code" class="cpp">#include "T06cclayers.h" T06cclayers::T06cclayers(void) { } T06cclayers::~T06cclayers(void) { } CCScene* T06cclayers::scene() { CCScene* scene = CCScene::create(); T06cclayers* layer = T06cclayers::create(); scene->addChild(layer); return scene; } bool T06cclayers::init() { cclayer::init(); CCSize size = CCDirector::sharedDirector()->sharedDirector()->getWinSize(); cclayerColor* layer = cclayerColor::create(ccc4(255,255),size.width / 2,size.height / 2); addChild(layer); return true; }
三、 cclayerGradient类
cclayerGradient* layer = cclayerGradient::create(ccc4(255,ccc4(0,255,ccp(1,1));
四、cclayerMutiplex
#include "T06cclayers.h" T06cclayers::T06cclayers(void) { } T06cclayers::~T06cclayers(void) { } CCScene* T06cclayers::scene() { CCScene* scene = CCScene::create(); T06cclayers* layer = T06cclayers::create(); scene->addChild(layer); return scene; } bool T06cclayers::init() { cclayer::init(); CCSize size = CCDirector::sharedDirector()->sharedDirector()->getWinSize(); cclayerColor* layer1 = cclayerColor::create(ccc4(255,size.height / 2); cclayerGradient* layer2 = cclayerGradient::create(ccc4(255,1)); cclayerMultiplex* layer = cclayerMultiplex::create(layer1,layer2,NULL); _id = 0; setTouchEnabled(true); _layer = layer; addChild(layer); return true; } void T06cclayers::cctouchesBegan(CCSet *ptouches,CCEvent *pEvent) { _id = 1 - _id; _layer ->switchTo(_id); }