Cocos Creator API

1.0.0

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

Color

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.

Properties

WHITE Color static

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

BLACK Color static

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

TRANSPARENT Color static

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

GRAY Color static

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

RED Color static

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

GREEN Color static

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

BLUE Color static

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

YELLOW Color static

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

ORANGE Color static

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

CYAN Color static

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

MAGENTA Color static

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

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

Methods

Color
(
  • [r =0]
  • [g =0]
  • [b =0]
  • [a =255]
)
Color

name type description
r optional Number 0

red component of the color, default value is 0.

g optional Number 0

green component of the color, defualt value is 0.

b optional Number 0

blue component of the color, default value is 0.

a optional Number 255

alpha component of the color, default value is 255.

returns:

type: Color

clone ( ) Color

Clone a new color from the current color.

returns:

type: Color

Newly created color.

examples:

var color = new cc.Color();
var newColor = color.clone();// Color {r: 0, g: 0, b: 0, a: 255}

equals
(
  • other
)
Boolean

TODO

name type description
other Color
  • r Number optional , default: 0

    red component of the color, default value is 0.

  • g Number optional , default: 0

    green component of the color, defualt value is 0.

  • b Number optional , default: 0

    blue component of the color, default value is 0.

  • a Number optional , default: 255

    alpha component of the color, default value is 255.

returns:

type: Boolean

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
(
  • to
  • ratio
  • [out ]
)
Color

TODO

name type description
to Color
  • r Number optional , default: 0

    red component of the color, default value is 0.

  • g Number optional , default: 0

    green component of the color, defualt value is 0.

  • b Number optional , default: 0

    blue component of the color, default value is 0.

  • a Number optional , default: 255

    alpha component of the color, default value is 255.

ratio number

the interpolation coefficient.

out optional Color

optional, the receiving vector.

  • r Number optional , default: 0

    red component of the color, default value is 0.

  • g Number optional , default: 0

    green component of the color, defualt value is 0.

  • b Number optional , default: 0

    blue component of the color, default value is 0.

  • a Number optional , default: 255

    alpha component of the color, default value is 255.

returns:

type: Color

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 ( ) String

TODO

returns:

type: String

examples:

var color = cc.Color.WHITE;
color.toString(); // "rgba(255, 255, 255, 255)"

setR
(
  • red
)
Color

TODO

name type description
red Number

the new Red component.

returns:

type: Color

this color.

examples:

var color = new cc.Color();
color.setR(255); // Color {r: 255, g: 0, b: 0, a: 255}

setG
(
  • green
)
Color

TODO

name type description
green Number

the new Green component.

returns:

type: Color

this color.

examples:

var color = new cc.Color();
color.setG(255); // Color {r: 0, g: 255, b: 0, a: 255}

setB
(
  • blue
)
Color

TODO

name type description
blue Number

the new Blue component.

returns:

type: Color

this color.

examples:

var color = new cc.Color();
color.setB(255); // Color {r: 0, g: 0, b: 255, a: 255}

setA
(
  • alpha
)
Color

TODO

name type description
alpha Number

the new Alpha component.

returns:

type: Color

this color.

examples:

var color = new cc.Color();
color.setA(0); // Color {r: 0, g: 0, b: 0, a: 0}

toCSS
(
  • opt
)
String

TODO

name type description
opt String

"rgba", "rgb", "#rgb" or "#rrggbb".

returns:

type: String

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";

clamp ( )

Clamp this color to make all components between 0 to 255。

examples:

var color = new cc.Color(1000, 0, 0, 255);
color.clamp();
cc.log(color); // (255, 0, 0, 255)

fromHEX
(
  • hexString
)
Color

TODO

name type description
hexString String

returns:

type: Color

examples:

var color = cc.Color.BLACK;
color.fromHEX("#FFFF33"); // Color {r: 255, g: 255, b: 51, a: 255};

toHEX
(
  • fmt
)
String

TODO

name type description
fmt String

"#rgb" or "#rrggbb".

returns:

type: String

examples:

var color = cc.Color.BLACK;
color.toHEX("#rgb");     // "000";
color.toHEX("#rrggbb");  // "000000";

toRGBValue ( ) Number

Convert to 24bit rgb value.

returns:

type: Number

examples:

var color = cc.Color.YELLOW;
color.toRGBValue(); // 16771844;

fromHSV
(
  • h
  • s
  • v
)
Color

TODO

name type description
h Number
s Number
v Number

returns:

type: Color

examples:

var color = cc.Color.YELLOW;
color.fromHSV(0, 0, 1); // Color {r: 255, g: 255, b: 255, a: 255};

toHSV ( ) Object

TODO

returns:

type: Object

{h: number, s: number, v: number}.

examples:

var color = cc.Color.YELLOW;
color.toHSV(); // Object {h: 0.1533864541832669, s: 0.9843137254901961, v: 1};

rgb2hsv
(
  • r
  • g
  • b
)
Object static

TODO

name type description
r Number

red, must be [0, 255].

g Number

red, must be [0, 255].

b Number

red, must be [0, 255].

returns:

type: Object

{h: number, s: number, v: number}.

examples:

cc.Color.rgb2hsv(255, 255, 255); // Object {h: 0, s: 0, v: 1};

hsv2rgb
(
  • h
  • s
  • v
)
Object static

TODO

name type description
h Number
s Number
v Number

returns:

type: Object

{r: number, g: number, b: number}}, rgb will be in [0, 255].

examples:

cc.Color.hsv2rgb(0, 0, 1); // Object {r: 255, g: 255, b: 255};

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index