Cocos Creator API

1.0.0

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

Rect

Extends ValueType
Module: cc

A 2D rectangle defined by x, y position and width, height.

Properties

xMin Number

TODO

yMin Number

TODO

xMax Number

TODO

yMax Number

TODO

center Number

TODO

size Size

TODO

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

Rect
(
  • [x =0]
  • [y =0]
  • [w =0]
  • [h =0]
)
Rect

Constructor of cc.Rect class. see cc.rect for convenience method.

name type description
x optional Number 0
y optional Number 0
w optional Number 0
h optional Number 0

returns:

type: Rect

fromMinMax
(
  • v1
  • v2
)
Rect static

Creates a rectangle from two coordinate values.

name type description
v1 Vec2
v2 Vec2

returns:

type: Rect

examples:

cc.Rect.fromMinMax(cc.v2(10, 10), cc.v2(20, 20)); // Rect {x: 10, y: 10, width: 10, height: 10};

contain
(
  • a
  • b
)
Number static

Checks if rect contains.

name type description
a Rect

Rect a

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0
b Rect

Rect b

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Number

The contains result, 1 is a contains b, -1 is b contains a, 0 is no contains.

examples:

var a = new cc.rect(0, 0, 10, 10);
var b = new cc.rect(5, 5, 5, 5);
var c = new cc.rect(20, 20, 10, 10);
cc.Rect.contain(a, b); //  1;
cc.Rect.contain(b, a); // -1;
cc.Rect.contain(a, c); //  0;

clone ( ) Rect

TODO

returns:

type: Rect

examples:

var a = new cc.rect(0, 0, 10, 10);
a.clone();// Rect {x: 0, y: 0, width: 10, height: 10}

equals
(
  • other
)
Boolean

TODO

name type description
other Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Boolean

examples:

var a = new cc.rect(0, 0, 10, 10);
var b = new cc.rect(0, 0, 10, 10);
a.equals(b);// true;

lerp
(
  • to
  • ratio
  • [out ]
)
Rect

TODO

name type description
to Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0
ratio Number

the interpolation coefficient.

out optional Rect

optional, the receiving vector.

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

returns:

type: Rect

examples:

var a = new cc.rect(0, 0, 10, 10);
var b = new cc.rect(50, 50, 100, 100);
update (dt) {
   // method 1;
   var c = a.lerp(b, dt * 0.1);
   // method 2;
   a.lerp(b, dt * 0.1, c);
}

toString ( ) String

TODO

returns:

type: String

examples:

var a = new cc.rect(0, 0, 10, 10);
a.toString();// "(0.00, 0.00, 10.00, 10.00)";

intersects
(
  • rect
)

TODO

name type description
rect Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

examples:

var a = new cc.rect(0, 0, 10, 10);
var b = new cc.rect(0, 0, 20, 20);
a.intersects(b);// true

contains
(
  • point
)

TODO

name type description
point Vec2

examples:

var a = new cc.rect(0, 0, 10, 10);
var b = new cc.v2(0, 5);
a.contains(b);// true

containsRect
(
  • rect
)

Returns true if the other rect totally inside this rectangle.

name type description
rect Rect

!#en Constructor of cc.Rect class. see cc.rect for convenience method. !#zh cc.Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

  • x Number optional , default: 0
  • y Number optional , default: 0
  • w Number optional , default: 0
  • h Number optional , default: 0

examples:

var a = new cc.rect(0, 0, 10, 10);
var b = new cc.rect(0, 0, 20, 20);
a.containsRect(b);// true

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