Color Component
Draw a colored rectangle.
Methods
Back to top
.color()
Events
- Invalidate
- when the color changes
Will assign the color and opacity, either through a string shorthand, or through explicit rgb values.
public this .color(String color[, Float strength])
- color
Color of the rectangle
- strength
the opacity of the rectangle
public this .color(r, g, b[, strength])
- r
value for the red channel
- g
value for the green channel
- b
value for the blue channel
- strength
the opacity of the rectangle
public String .color()
- [Returns]
A string representing the current color as a CSS property.
Example
var c = Crafty.e("2D, DOM, Color");
c.color("#FF0000");
c.color("red");
c.color(255, 0, 0);
c.color("rgb(255, 0, 0)");
Three different ways of assign the color red.
var c = Crafty.e("2D, DOM, Color");
c.color("#00FF00", 0.5);
c.color("rgba(0, 255, 0, 0.5)");
Two ways of assigning a transparent green color.