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
y
width
height
xMin
The minimum x value, equals to rect.x
yMin
The minimum y value, equals to rect.y
xMax
The maximum x value.
yMax
The maximum y value.
center
The position of the center of the rectangle.
origin
The X and Y position of the rectangle.
size
Width and height of the rectangle.
Methods
constructor
Constructor of Rect class.
see cc.rect for convenience method.
Parameters
fromMinMax
Creates a rectangle from two coordinate values.
Parameters
Examples
cc.Rect.fromMinMax(cc.v2(10, 10), cc.v2(20, 20));
clone
TODO
Examples
var a = new cc.Rect(0, 0, 10, 10);
a.clone();
equals
TODO
Parameters
Examples
var a = new cc.Rect(0, 0, 10, 10);
var b = new cc.Rect(0, 0, 10, 10);
a.equals(b);
lerp
TODO
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) {
var c = a.lerp(b, dt * 0.1);
a.lerp(b, dt * 0.1, c);
}
intersects
Check whether the current rectangle intersects with the given one
Parameters
Examples
var a = new cc.Rect(0, 0, 10, 10);
var b = new cc.Rect(0, 0, 20, 20);
a.intersects(b);
intersection
Returns the overlapping portion of 2 rectangles.
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);
contains
Check whether the current rect contains the given point
Parameters
Examples
var a = new cc.Rect(0, 0, 10, 10);
var b = new cc.Vec2(0, 5);
a.contains(b);
containsRect
Returns true if the other rect totally inside this rectangle.
Parameters
Examples
var a = new cc.Rect(0, 0, 20, 20);
var b = new cc.Rect(0, 0, 10, 10);
a.containsRect(b);
union
Returns the smallest rectangle that contains the current rect and the given rect.
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);
Apply matrix4 to the rect.
Parameters
out
Rect The output rect
mat
Mat4 The matrix4
toString
Output rect informations to string
Examples
var a = new cc.Rect(0, 0, 10, 10);
a.toString();
set
Copys all the properties from another given object to this value.
Parameters