Cocos2dx之CCLayer层

前端之家收集整理的这篇文章主要介绍了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);
}
原文链接:https://www.f2er.com/cocos2dx/341988.html

猜你在找的Cocos2d-x相关文章