LayerColor和LayerGradient

本文介绍Cocos2d-x中LayerColor和LayerGradient的使用方法,包括如何创建不同颜色及渐变效果的层,并通过示例展示如何设置层的位置和渐变方向。

    /** creates a Layer with color, width and height in Points */  

//创建一个指定宽高大小的额颜色层

    static LayerColor * create(const Color4B& color, GLfloat width, GLfloat height);


//创建一个颜色层,默认其大小和当前窗口大小相同

    /** creates a Layer with color. Width and height are the window size. */

    static LayerColor * create(const Color4B& color);

实例:

auto layerColorGB = cocos2d::LayerColor::create((cocos2d::Color4B(244, 164, 96, 255)));
addChild(layerColorGB);

可以指定其位置,但是锚点位置无用,需要调用 ignoreAnchorPointForPosition才能再使用锚点;



LayerGradient创建一个带有颜色渐变的层


    /** Creates a full-screen Layer with a gradient between start and end. */

//创建一个充满屏幕的渐变层,默认从上往下渐变
    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. */

//创建一个充满屏幕,带渐变方向的颜色层

    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)从右上往左下渐变


getStartOpacity   返回渐变的起始透明度


void setVector(const Vec2 & alongVector)设置将用于渐变的方向向量。默认值是垂直方向(0,-1)。从上往下渐变。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值