Cocos Creator API

1.3.0

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

Color

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.

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

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

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.

:

: Color

clone ( ) Color

Clone a new color from the current color.

:

: Color

Newly created color.

:

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

equals
(
  • other
)
Boolean

TODO

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.

:

:

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

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.

:

: Color

:

// 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

:

: String

:

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

setR
(
  • red
)
Color

TODO

red Number

the new Red component.

:

: Color

this color.

:

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

setG
(
  • green
)
Color

TODO

green Number

the new Green component.

:

: Color

this color.

:

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

setB
(
  • blue
)
Color

TODO

blue Number

the new Blue component.

:

: Color

this color.

:

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

setA
(
  • alpha
)
Color

TODO

alpha Number

the new Alpha component.

:

: Color

this color.

:

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

toCSS
(
  • opt
)
String

TODO

opt String

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

:

: String

:

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。

:

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

fromHEX
(
  • hexString
)
Color

TODO

hexString String

:

: Color

:

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

toHEX
(
  • fmt
)
String

TODO

fmt String

"#rgb" or "#rrggbb".

:

: String

:

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

toRGBValue ( ) Number

Convert to 24bit rgb value.

:

: Number

:

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

fromHSV
(
  • h
  • s
  • v
)
Color

TODO

:

: Color

:

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

toHSV ( ) Object

TODO

:

: Object

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

:

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

rgb2hsv
(
  • r
  • g
  • b
)
Object static

TODO

r Number

red, must be [0, 255].

g Number

red, must be [0, 255].

b Number

red, must be [0, 255].

:

: Object

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

:

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

hsv2rgb
(
  • h
  • s
  • v
)
Object static

TODO

:

: Object

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

:

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