首页 技术 正文
技术 2022年11月12日
0 收藏 802 点赞 2,768 浏览 1865 个字

1.CCLayerColor是专门用来处理背景颜色的图层,它继承自CCLayer,可以用来设置图层的背景颜色,因为CCLayer默认是透明色的,即无颜色的

2.CCLayerGradient是用来显示颜色渐变效果的图层,它继承自CCLayerColor,是CCLayer的孙类

3.几个特殊的图层:CCLayerColor,CCLayerGradient
  颜色图层在游戏中主要用来烘托背景,可以按照RGB设置填充颜色,同时还可以设置图层的透明度,常用于背景
 
  颜色图层还存在一个特殊的子类:CCLayerGradient,是具有颜色渐变效果的颜色图层
  可以设置背景的渐变效果,Opacity:透明度

4.相关的处理函数:

bool CCLayerColor::initWithColor(const ccColor4B& color);
bool CCLayerColor::initWithColor(const ccColor4B& color, GLfloat w,GLfloat h);

实例:

CCLayerColor::initWithColor(ccc4(255, 255, 255, 255));
CCLayerColor::initWithColor(ccc4(255, 255, 255, 255),100,100);
ignoreAnchorPointForPosition(false);

bool CCLayerGradient::initWithColor(const ccColor4B& start, const ccColor4B& end);
bool CCLayerGradient::initWithColor(const ccColor4B& start, const ccColor4B& end, const CCPoint& v);

实例:

CCLayerGradient::initWithColor(ccc4(123,89,0,255),
ccc4(0,255,255,255),ccp(1,0));

5.代码实现:

.h文件

#ifndef __T04ColorLayer_H__
#define __T04ColorLayer_H__#include "cocos2d.h"
USING_NS_CC;/*CCLayer默认的背景颜色是透明的,而CCLayerColor图层,可以设置背景颜色*/
class T04ColorLayer :public CCLayerColor
{
public:
static CCScene * scene();
CREATE_FUNC(T04ColorLayer);
bool init();};#endif

.cpp文件

#include "T04ColorLayer.h"/*CCLayerGradient可以设置颜色的渐变梯度,class CCLayerGradient : public CCLayerColor*/
class LayerGradient :public CCLayerGradient
{
public:
CREATE_FUNC(LayerGradient);
bool init()
{
/** Initializes the CCLayer with a gradient between start and end in the direction of v.
virtual bool initWithColor(const ccColor4B& start, const ccColor4B& end, const CCPoint& v);
**/
CCLayerGradient::initWithColor(ccc4(, , , ), ccc4(, , , ), ccp(, )); return true;
}};CCScene *T04ColorLayer::scene()
{
CCScene * scene = CCScene::create(); /*测试背景图层*/
T04ColorLayer * layer = T04ColorLayer::create(); /*测试渐变图层*/
//LayerGradient * layer = LayerGradient::create(); scene->addChild(layer);
return scene;
}
bool T04ColorLayer::init()
{
CCLayerColor::initWithColor(ccc4(, , , ), , ); /*设置不忽略锚点,在CCLayer和CCScene中默认是忽略锚点的,*/
ignoreAnchorPointForPosition(false); return true;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295