Rect Class

Extends ValueType

Module: cc Parent 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.ts:77
y
meta description
Type Number
Defined in cocos2d/core/value-types/rect.ts:81
width
meta description
Type Number
Defined in cocos2d/core/value-types/rect.ts:85
height
meta description
Type Number
Defined in cocos2d/core/value-types/rect.ts:89
xMin

The minimum x value, equals to rect.x

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

The minimum y value, equals to rect.y

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

The maximum x value.

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

The maximum y value.

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

The position of the center of the rectangle.

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

The X and Y position of the rectangle.

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

Width and height of the rectangle.

meta description
Type Size
Defined in cocos2d/core/value-types/rect.ts:411

Methods

constructor

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

meta description
Defined in cocos2d/core/value-types/rect.ts:42
Parameters
fromMinMax

Creates a rectangle from two coordinate values.

meta description
Returns Rect
Defined in cocos2d/core/value-types/rect.ts:57
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.ts:108
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.ts:121
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.ts:140
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.ts:179
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.ts:198
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.ts:221
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.ts:240
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.ts:258
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.ts:281
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.ts:315
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.ts:80
Parameters

results matching ""

    No results matching ""