Color 组件

绘制一个带颜色的矩形。

方法

Back to top

.color()

事件

Invalidate
当颜色改变时触发

设置颜色和透明度,可以通过一个速记字符串或者RGB颜色值。

public this .color(String color[, Float strength])
color

矩形的颜色

strength

矩形的透明度

public this .color(r, g, b[, strength])
r

红色通道的值

g

绿色通道的值

b

蓝色通道的值

strength

矩形的透明度

public String .color()
[Returns]

表示当前颜色的CSS属性。

例子

var c = Crafty.e("2D, DOM, Color");
c.color("#FF0000");
c.color("red");
c.color(255, 0, 0);
c.color("rgb(255, 0, 0)");

三种不同的方法将颜色设置为红色

var c = Crafty.e("2D, DOM, Color");
c.color("#00FF00", 0.5);
c.color("rgba(0, 255, 0, 0.5)");

分配透明绿色的两种方法。