Color Class

Extends ValueType

Module: cc

Representation of RGBA colors.

Each color component is a floating point value with a range from 0 to 255.

You can also use the convenience method cc.color to create a new Color.

Index

Properties
  • WHITE Color Solid white, RGBA is [255, 255, 255, 255].
  • BLACK Color Solid black, RGBA is [0, 0, 0, 255].
  • TRANSPARENT Color Transparent, RGBA is [0, 0, 0, 0].
  • GRAY Color Grey, RGBA is [127.5, 127.5, 127.5].
  • RED Color Solid red, RGBA is [255, 0, 0].
  • GREEN Color Solid green, RGBA is [0, 255, 0].
  • BLUE Color Solid blue, RGBA is [0, 0, 255].
  • YELLOW Color Yellow, RGBA is [255, 235, 4].
  • ORANGE Color Orange, RGBA is [255, 127, 0].
  • CYAN Color Cyan, RGBA is [0, 255, 255].
  • MAGENTA Color Magenta, RGBA is [255, 0, 255].
Methods
  • constructor
  • clone Clone a new color from the current color.
  • equals TODO
  • lerp TODO
  • toString TODO
  • getR Gets red channel value
  • setR Sets red value and return the current color object
  • getG Gets green channel value
  • setG Sets green value and return the current color object
  • getB Gets blue channel value
  • setB Sets blue value and return the current color object
  • getA Gets alpha channel value
  • setA Sets alpha value and return the current color object
  • toCSS Convert color to css format.
  • fromHEX Read hex string and store color data into the current color object, the hex string must be formated as rgba or rgb.
  • toHEX convert Color to HEX color string.
  • toRGBValue Convert to 24bit rgb value.
  • fromHSV Read HSV model color and convert to RGB color
  • toHSV Transform to HSV model color
  • set Copys all the properties from another given object to this value.

Details

Properties

WHITE

Solid white, RGBA is [255, 255, 255, 255].

meta description
Type Color
Defined in cocos2d/core/value-types/color.js:81
BLACK

Solid black, RGBA is [0, 0, 0, 255].

meta description
Type Color
Defined in cocos2d/core/value-types/color.js:89
TRANSPARENT

Transparent, RGBA is [0, 0, 0, 0].

meta description
Type Color
Defined in cocos2d/core/value-types/color.js:97
GRAY

Grey, RGBA is [127.5, 127.5, 127.5].

meta description
Type Color
Defined in cocos2d/core/value-types/color.js:105
RED

Solid red, RGBA is [255, 0, 0].

meta description
Type Color
Defined in cocos2d/core/value-types/color.js:113
GREEN

Solid green, RGBA is [0, 255, 0].

meta description
Type Color
Defined in cocos2d/core/value-types/color.js:121
BLUE

Solid blue, RGBA is [0, 0, 255].

meta description
Type Color
Defined in cocos2d/core/value-types/color.js:129
YELLOW

Yellow, RGBA is [255, 235, 4].

meta description
Type Color
Defined in cocos2d/core/value-types/color.js:137
ORANGE

Orange, RGBA is [255, 127, 0].

meta description
Type Color
Defined in cocos2d/core/value-types/color.js:145
CYAN

Cyan, RGBA is [0, 255, 255].

meta description
Type Color
Defined in cocos2d/core/value-types/color.js:153
MAGENTA

Magenta, RGBA is [255, 0, 255].

meta description
Type Color
Defined in cocos2d/core/value-types/color.js:161

Methods

constructor
meta description
Defined in cocos2d/core/value-types/color.js:56
Parameters
  • r Number red component of the color, default value is 0.
  • g Number green component of the color, defualt value is 0.
  • b Number blue component of the color, default value is 0.
  • a Number alpha component of the color, default value is 255.
clone

Clone a new color from the current color.

meta description
Returns Color
Defined in cocos2d/core/value-types/color.js:180
Examples
var color = new cc.Color();
var newColor = color.clone();// Color {r: 0, g: 0, b: 0, a: 255}
equals

TODO

meta description
Returns Boolean
Defined in cocos2d/core/value-types/color.js:195
Parameters
Examples
var color1 = cc.Color.WHITE;
var color2 = new cc.Color(255, 255, 255);
cc.log(color1.equals(color2)); // true;
color2 = cc.Color.RED;
cc.log(color2.equals(color1)); // false;
lerp

TODO

meta description
Returns Color
Defined in cocos2d/core/value-types/color.js:212
Parameters
  • to Color
  • ratio number the interpolation coefficient.
  • out Color optional, the receiving vector.
Examples
// Converts a white color to a black one trough time.
update: function (dt) {
    var color = this.node.color;
    if (color.equals(cc.Color.BLACK)) {
        return;
    }
    this.ratio += dt * 0.1;
    this.node.color = cc.Color.WHITE.lerp(cc.Color.BLACK, ratio);
}
toString

TODO

meta description
Returns String
Defined in cocos2d/core/value-types/color.js:235
Examples
var color = cc.Color.WHITE;
color.toString(); // "rgba(255, 255, 255, 255)"
getR

Gets red channel value

meta description
Returns Number
Defined in cocos2d/core/value-types/color.js:252
setR

Sets red value and return the current color object

meta description
Returns Color
Defined in cocos2d/core/value-types/color.js:261
Parameters
  • red Number the new Red component.
Examples
var color = new cc.Color();
color.setR(255); // Color {r: 255, g: 0, b: 0, a: 255}
getG

Gets green channel value

meta description
Returns Number
Defined in cocos2d/core/value-types/color.js:276
setG

Sets green value and return the current color object

meta description
Returns Color
Defined in cocos2d/core/value-types/color.js:285
Parameters
  • green Number the new Green component.
Examples
var color = new cc.Color();
color.setG(255); // Color {r: 0, g: 255, b: 0, a: 255}
getB

Gets blue channel value

meta description
Returns Number
Defined in cocos2d/core/value-types/color.js:300
setB

Sets blue value and return the current color object

meta description
Returns Color
Defined in cocos2d/core/value-types/color.js:309
Parameters
  • blue Number the new Blue component.
Examples
var color = new cc.Color();
color.setB(255); // Color {r: 0, g: 0, b: 255, a: 255}
getA

Gets alpha channel value

meta description
Returns Number
Defined in cocos2d/core/value-types/color.js:324
setA

Sets alpha value and return the current color object

meta description
Returns Color
Defined in cocos2d/core/value-types/color.js:333
Parameters
  • alpha Number the new Alpha component.
Examples
var color = new cc.Color();
color.setA(0); // Color {r: 0, g: 0, b: 0, a: 0}
toCSS

Convert color to css format.

meta description
Returns String
Defined in cocos2d/core/value-types/color.js:358
Parameters
  • opt String "rgba", "rgb", "#rgb" or "#rrggbb".
Examples
var color = cc.Color.BLACK;
color.toCSS();          // "#000";
color.toCSS("rgba");    // "rgba(0,0,0,1.00)";
color.toCSS("rgb");     // "rgba(0,0,0)";
color.toCSS("#rgb");    // "#000";
color.toCSS("#rrggbb"); // "#000000";
fromHEX

Read hex string and store color data into the current color object, the hex string must be formated as rgba or rgb.

meta description
Returns Color
Defined in cocos2d/core/value-types/color.js:387
Parameters
Examples
var color = cc.Color.BLACK;
color.fromHEX("#FFFF33"); // Color {r: 255, g: 255, b: 51, a: 255};
toHEX

convert Color to HEX color string. e.g. cc.color(255,6,255) to : "#ff06ff"

meta description
Returns String
Defined in cocos2d/core/value-types/color.js:408
Parameters
  • fmt String "#rgb", "#rrggbb" or "#rrggbbaa".
Examples
var color = cc.Color.BLACK;
color.toHEX("#rgb");     // "000";
color.toHEX("#rrggbb");  // "000000";
toRGBValue

Convert to 24bit rgb value.

meta description
Returns Number
Defined in cocos2d/core/value-types/color.js:448
Examples
var color = cc.Color.YELLOW;
color.toRGBValue(); // 16771844;
fromHSV

Read HSV model color and convert to RGB color

meta description
Returns Color
Defined in cocos2d/core/value-types/color.js:461
Parameters
Examples
var color = cc.Color.YELLOW;
color.fromHSV(0, 0, 1); // Color {r: 255, g: 255, b: 255, a: 255};
toHSV

Transform to HSV model color

meta description
Returns Object
Defined in cocos2d/core/value-types/color.js:539
Examples
var color = cc.Color.YELLOW;
color.toHSV(); // Object {h: 0.1533864541832669, s: 0.9843137254901961, v: 1};
set

Copys all the properties from another given object to this value.

meta description
Defined in cocos2d/core/value-types/value-type.js:84
Parameters

results matching ""

    No results matching ""