Cocos Creator API

1.5.x

Cocos Creator is the game engine for the future.

Rect

Extends ValueType
Module: cc
Parent Module: cc

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

Properties

x Number

y Number

width Number

height Number

xMin Number

TODO

yMin Number

TODO

xMax Number

TODO

yMax Number

TODO

center Vec2

The position of the center of the rectangle.

origin Vec2

The X and Y position of the rectangle.

size Size

Width and height of the rectangle.

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

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

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

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

b Rect

Rect b

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

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
ratio Number

the interpolation coefficient.

out optional Rect

optional, the receiving vector.

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

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.Vec2(0, 5);
a.contains(b);// true

containsRect
(
  • rect
)

Returns true if the other rect totally inside this rectangle.

name type description
rect Rect

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