Cocos2dx之CCLayer层

一、层的概念

我们从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);
}

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...