/** creates a Layer with color, width and height in Points */
//创建一个指定宽高大小的额颜色层
static LayerColor * create(const Color4B& color, GLfloat width, GLfloat height);
//创建一个颜色层,默认其大小和当前窗口大小相同
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)从右上往左下渐变
void setVector(const Vec2 & alongVector)设置将用于渐变的方向向量。默认值是垂直方向(0,-1)。从上往下渐变。
本文介绍Cocos2d-x中LayerColor和LayerGradient的使用方法,包括如何创建不同颜色及渐变效果的层,并通过示例展示如何设置层的位置和渐变方向。
491

被折叠的 条评论
为什么被折叠?



