颜色布景层类LayerColor

颜色布景层类LayerColor是Layer的子类,包含Layer类的特性,并且有两个拓展功能:为布景层增添颜色以及设置不透明度。

分析其源码:

class CC_DLL LayerColor : public Layer, public BlendProtocol
{
public:/** Creates a fullscreen black layer.** @return An autoreleased LayerColor object.*/static LayerColor* create();/** Creates a Layer with color, width and height in Points.** @param color The color of layer.* @param width The width of layer.* @param height The height of layer.* @return An autoreleased LayerColor object.*/static LayerColor * create(const Color4B& color, GLfloat width, GLfloat height);/** Creates a Layer with color. Width and height are the window size.** @param color The color of layer.* @return An autoreleased LayerColor object.*/static LayerColor * create(const Color4B& color);/** Change width in Points.* * @param w The width of layer.*/void changeWidth(GLfloat w);/** Change height in Points.** @param h The height of layer.*/void changeHeight(GLfloat h);/** Change width and height in Points.* * @param w The width of layer.* @param h The Height of layer.@since v0.8*/void changeWidthAndHeight(GLfloat w ,GLfloat h);//// Overrides//virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;virtual void setContentSize(const Size & var) override;/** BlendFunction. Conforms to BlendProtocol protocol *//*** @lua NA*/virtual const BlendFunc& getBlendFunc() const override;/***@code*When this function bound into js or lua,the parameter will be changed*In js: var setBlendFunc(var src, var dst)*In lua: local setBlendFunc(local src, local dst)*@endcode*/virtual void setBlendFunc(const BlendFunc& blendFunc) override;virtual std::string getDescription() const override;CC_CONSTRUCTOR_ACCESS:LayerColor();virtual ~LayerColor();bool init() override;bool initWithColor(const Color4B& color, GLfloat width, GLfloat height);bool initWithColor(const Color4B& color);protected:void onDraw(const Mat4& transform, uint32_t flags);virtual void updateColor() override;BlendFunc _blendFunc;Vec2 _squareVertices[4];Color4F  _squareColors[4];CustomCommand _customCommand;Vec3 _noMVPVertices[4];
private:CC_DISALLOW_COPY_AND_ASSIGN(LayerColor);};

主要用法举例如下:

 auto colorBack = LayerColor::create( Color4B(170,170,170,255),64*4+4*5, 64*4+4*5);colorBack->ignoreAnchorPointForPosition(false);colorBack->setAnchorPoint(Point(0.5,0.5));colorBack->setPosition(Point(visiblesize.width/2, visiblesize.height/2));this->addChild(colorBack);

重点说明这句:colorBack->ignoreAnchorPointForPosition(false);

使用ignoreAnchorPointForPosition将是否忽略锚点置为false,由于是否忽略锚点的默认值是true,也就是忽略锚点,而以左下角为锚点。可以让布景层考虑锚点的影响

展示效果:

带有颜色渐变布景层类LayerGradient

class CC_DLL LayerGradient : public LayerColor
{
public:/** Creates a fullscreen black layer.** @return An autoreleased LayerGradient object.*/static LayerGradient* create();/** Creates a full-screen Layer with a gradient between start and end.** @param start The start color.* @param end The end color.* @return An autoreleased LayerGradient object.*/static LayerGradient* create(const Color4B& start, const Color4B& end);/** Creates a full-screen Layer with a gradient between start and end in the direction of v.** @param start The start color.* @param end The end color.* @param v The direction of gradient color.* @return An autoreleased LayerGradient object.*/static LayerGradient* create(const Color4B& start, const Color4B& end, const Vec2& v);Vec2(1,0)从左往右渐变Vec2(-1,0)从右往左渐变Vec2(0,1) 从下往上渐变Vec2(0,-1)从上往下渐变Vec2(1,1)从左下往右上渐变Vec2(-1,1)从右下往左上渐变Vec2(1,-1) 从左上往右下渐变Vec2(-1,-1)从右上往左下渐变/** Whether or not the interpolation will be compressed in order to display all the colors of the gradient both in canonical and non canonical vectors.Default: true.** @param compressedInterpolation The interpolation will be compressed if true.*/void setCompressedInterpolation(bool compressedInterpolation);/** Get the compressedInterpolation** @return The interpolation will be compressed if true.*/bool isCompressedInterpolation() const;/** Sets the start color of the gradient.* * @param startColor The start color.*/void setStartColor( const Color3B& startColor );/** Returns the start color of the gradient.** @return The start color.*/const Color3B& getStartColor() const;/** Sets the end color of the gradient.** @param endColor The end color.*/void setEndColor( const Color3B& endColor );/** Returns the end color of the gradient.** @return The end color.*/const Color3B& getEndColor() const;/** Returns the start opacity of the gradient.** @param startOpacity The start opacity, from 0 to 255.*/void setStartOpacity( GLubyte startOpacity );/** Returns the start opacity of the gradient.** @return The start opacity.*/GLubyte getStartOpacity() const;/** Returns the end opacity of the gradient.** @param endOpacity The end opacity, from 0 to 255.*/void setEndOpacity( GLubyte endOpacity );/** Returns the end opacity of the gradient.** @return The end opacity.*/GLubyte getEndOpacity() const;/** Sets the directional vector that will be used for the gradient.The default value is vertical direction (0,-1). ** @param alongVector The direction of gradient.*/void setVector(const Vec2& alongVector);/** Returns the directional vector used for the gradient.** @return The direction of gradient.*/const Vec2& getVector() const;virtual std::string getDescription() const override;CC_CONSTRUCTOR_ACCESS:LayerGradient();virtual ~LayerGradient();virtual bool init() override;/** Initializes the Layer with a gradient between start and end.* @js init* @lua init*/bool initWithColor(const Color4B& start, const Color4B& end);/** Initializes the Layer with a gradient between start and end in the direction of v.* @js init* @lua init*/bool initWithColor(const Color4B& start, const Color4B& end, const Vec2& v);protected:virtual void updateColor() override;Color3B _startColor;Color3B _endColor;GLubyte _startOpacity;GLubyte _endOpacity;Vec2   _alongVector;bool    _compressedInterpolation;
};

具体实例:

LayerGradient* layergradient = LayerGradient::create(Color4B(0,255,0,0),Color4B(0,0,255,255));addChild(layergradient);

内置的常用层:LayerColor、LayerGradient相关推荐

  1. Cocos2d-x内置的常用层

    为了方便游戏开发者,Cocos2d-x内置了3种特殊的CCLayer,具体如下所示.  CCLayerColor:一个单纯的实心色块. CCLayerGradient:一个色块,但可以设置两种颜色的渐 ...

  2. 内置的常用协议实现模版

    SuperSocket 内置的常用协议实现模版 中文(中国)Toggle Dropdown v1.6Toggle Dropdown 关键字: TerminatorReceiveFilter, Coun ...

  3. python operator 多属性排序_又碰到一个非常实用的模块,以后的各种运算就用它了,python内置的常用包。

    在工作中,经常对数据进行各种运算,如要从一个序列中返回一个新的序列,亦或是要对两个数进行比较或者进行加和操作等.如果只是一个简单的运算,怎么都好办.但如果我们面对的是比较复杂的需求时,可能我们更多的是 ...

  4. 零基础学Python(第二十二章 常用内置函数)

    本套学习内容共计[22]个章节,每个章节都会有对应的从0-1的学习过程详细讲解,希望可以给更多的人提供帮助. 开发环境:[Win10] 开发工具:[Visual Studio 2019] 本章内容为: ...

  5. python 全栈开发,Day51(常用内置对象,函数,伪数组 arguments,关于DOM的事件操作,DOM介绍)...

    昨日内容回顾 1.三种引入方式1.行内js <div onclick = 'add(3,4)'></div>//声明一个函数function add(a,b){}2.内接js& ...

  6. Python生成器的send方法、递推函数、匿名函数及常用内置函数

    1.生成器的send方法 在使用yield方法创建生成器时,不仅可以使用next方法进行取值,还可以通过send方法向生成器的内部传值 1.1 什么是send方法? send方法相当于高级的next方 ...

  7. 前端JavaScript(2) --常用内置对象,函数,伪数组 arguments,关于DOM的事件操作,DOM介绍...

    昨日内容回顾 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ...

  8. JSP第四课:用户注册登录设计(内置对象使用)

     一.相关知识:内置对象使用 客户端的浏览器从Web服务器上获得网页,实际上是使用HTTP协议向服务器发送一个请求,服务器在接收到来自客户端浏览器发来的请求后要响应请求.JSP通过request对象获 ...

  9. Python(8):模块内置变量

    写在前面 文章目录 模块内置变量 常用内置变量 __name__变量 __package__变量 __file__变量 __doc__变量 专栏目录 模块内置变量 常用内置变量 __name__变量 ...

  10. python函数type的用意_Python内置函数Type()函数一个有趣的用法

    Python内置函数Type()函数一个有趣的用法 今天在网上看到type的一段代码 ,然后查了一下文档,才知道type还有三个参数的用法. 以前只是知道type可以检测对象类型.然后发现了一个有趣的 ...

最新文章

  1. Java日期相关类:Date、SimpleDateFormat和Calendar类常用API代码示例
  2. 公共方法-利用for else搜索字典列表-for else
  3. (上)python3 selenium3 从框架实现代码学习selenium让你事半功倍
  4. jsf按钮响应事件_如何从JSF获取JSON响应?
  5. OC 中 load 方法和 initialize 方法的异同
  6. MongoDB 教程索引 (附有视频)
  7. 如何不让tomcat在启动时弹窗_Tomcat 在 Spring Boot 中是如何启动的
  8. 20165323 第一周学习总结
  9. hadoop 关闭datanode节点时发生异常:no datanode to stop
  10. 执行力 - 快速反应
  11. 索尼Fn键-亮度调节快捷键驱动
  12. windows_2008_server无法安装vcredist_x64
  13. 李永乐线性代数辅导讲义第四章学霸小结
  14. Linux下设置网卡速率 降低网卡速度
  15. Titan XP值不值?教你如何挑选深度学习GPU
  16. ie8 阻止java运行_解决IE屏蔽Java Applet问题的方法
  17. 如何卸载干净MySQL??
  18. 《周志明的软件架构课》学习笔记 Day15
  19. 让OpenAi给我写个JS的set对象的笔记和快速去重方法
  20. 基本面分析:原理、类型和使用方法

热门文章

  1. ThreadPoolExecutor 的三种提交任务方式
  2. 英特尔逆天原型机:在 Android 上跑 Debian
  3. AJAX初始化combox 并取值
  4. HttpStatusCode 枚举
  5. C++中的extern C【转】
  6. cactiez的monitor主机名乱码
  7. 既然Java反射可以访问和修改私有成员变量,那封装成private还有什么意义
  8. 居中为什么用transform,而不是margin top/left
  9. 数据库备份与还原的过程中介质集有2个介质簇,但只提供了1个。必须提供所有成员...
  10. 关于禁止ViewPager预加载问题【转】