Rect Class

Extends ValueType

Module: cc

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

Index

Properties
  • x Number
  • y Number
  • width Number
  • height Number
  • xMin Number The minimum x value, equals to rect.x
  • yMin Number The minimum y value, equals to rect.y
  • xMax Number The maximum x value.
  • yMax Number The maximum y value.
  • 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.
Methods
  • constructor Constructor of Rect class.
  • fromMinMax Creates a rectangle from two coordinate values.
  • clone TODO
  • equals TODO
  • lerp TODO
  • intersects Check whether the current rectangle intersects with the given one
  • intersection Returns the overlapping portion of 2 rectangles.
  • contains Check whether the current rect contains the given point
  • containsRect Returns true if the other rect totally inside this rectangle.
  • union Returns the smallest rectangle that contains the current rect and the given rect.
  • transformMat4 Apply matrix4 to the rect.
  • toString Output rect informations to string
  • set Copys all the properties from another given object to this value.

Details

Properties

x
meta description
Type Number
Defined in cocos2d/core/value-types/rect.js:67
y
meta description
Type Number
Defined in cocos2d/core/value-types/rect.js:70
width
meta description
Type Number
Defined in cocos2d/core/value-types/rect.js:73
height
meta description
Type Number
Defined in cocos2d/core/value-types/rect.js:76
xMin

The minimum x value, equals to rect.x

meta description
Type Number
Defined in cocos2d/core/value-types/rect.js:321
yMin

The minimum y value, equals to rect.y

meta description
Type Number
Defined in cocos2d/core/value-types/rect.js:335
xMax

The maximum x value.

meta description
Type Number
Defined in cocos2d/core/value-types/rect.js:349
yMax

The maximum y value.

meta description
Type Number
Defined in cocos2d/core/value-types/rect.js:360
center

The position of the center of the rectangle.

meta description
Type Vec2
Defined in cocos2d/core/value-types/rect.js:371
origin

The X and Y position of the rectangle.

meta description
Type Vec2
Defined in cocos2d/core/value-types/rect.js:387
size

Width and height of the rectangle.

meta description
Type Size
Defined in cocos2d/core/value-types/rect.js:402

Methods

constructor

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

meta description
Defined in cocos2d/core/value-types/rect.js:39
Parameters
fromMinMax

Creates a rectangle from two coordinate values.

meta description
Returns Rect
Defined in cocos2d/core/value-types/rect.js:80
Parameters
Examples
cc.Rect.fromMinMax(cc.v2(10, 10), cc.v2(20, 20)); // Rect {x: 10, y: 10, width: 10, height: 10};
clone

TODO

meta description
Returns Rect
Defined in cocos2d/core/value-types/rect.js:102
Examples
var a = new cc.Rect(0, 0, 10, 10);
a.clone();// Rect {x: 0, y: 0, width: 10, height: 10}
equals

TODO

meta description
Returns Boolean
Defined in cocos2d/core/value-types/rect.js:115
Parameters
Examples
var a = new cc.Rect(0, 0, 10, 10);
var b = new cc.Rect(0, 0, 10, 10);
a.equals(b);// true;
lerp

TODO

meta description
Returns Rect
Defined in cocos2d/core/value-types/rect.js:134
Parameters
  • to Rect
  • ratio Number the interpolation coefficient.
  • out Rect optional, the receiving vector.
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);
}
intersects

Check whether the current rectangle intersects with the given one

meta description
Returns Boolean
Defined in cocos2d/core/value-types/rect.js:172
Parameters
Examples
var a = new cc.Rect(0, 0, 10, 10);
var b = new cc.Rect(0, 0, 20, 20);
a.intersects(b);// true
intersection

Returns the overlapping portion of 2 rectangles.

meta description
Returns Rect
Defined in cocos2d/core/value-types/rect.js:191
Parameters
Examples
var a = new cc.Rect(0, 10, 20, 20);
var b = new cc.Rect(0, 10, 10, 10);
var intersection = new cc.Rect();
a.intersection(intersection, b); // intersection {x: 0, y: 10, width: 10, height: 10};
contains

Check whether the current rect contains the given point

meta description
Returns Boolean
Defined in cocos2d/core/value-types/rect.js:214
Parameters
Examples
var a = new cc.Rect(0, 0, 10, 10);
var b = new cc.Vec2(0, 5);
a.contains(b);// true
containsRect

Returns true if the other rect totally inside this rectangle.

meta description
Returns Boolean
Defined in cocos2d/core/value-types/rect.js:233
Parameters
Examples
var a = new cc.Rect(0, 0, 20, 20);
var b = new cc.Rect(0, 0, 10, 10);
a.containsRect(b);// true
union

Returns the smallest rectangle that contains the current rect and the given rect.

meta description
Returns Rect
Defined in cocos2d/core/value-types/rect.js:251
Parameters
Examples
var a = new cc.Rect(0, 10, 20, 20);
var b = new cc.Rect(0, 10, 10, 10);
var union = new cc.Rect();
a.union(union, b); // union {x: 0, y: 10, width: 20, height: 20};
transformMat4

Apply matrix4 to the rect.

meta description
Defined in cocos2d/core/value-types/rect.js:274
Parameters
  • out Rect The output rect
  • mat Mat4 The matrix4
toString

Output rect informations to string

meta description
Returns String
Defined in cocos2d/core/value-types/rect.js:307
Examples
var a = new cc.Rect(0, 0, 10, 10);
a.toString();// "(0.00, 0.00, 10.00, 10.00)";
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 ""