Rect 类型
继承于 ValueType
通过位置和宽高定义的 2D 矩形。
索引
属性(properties)
xNumberyNumberwidthNumberheightNumberxMinNumber矩形 x 轴上的最小值,等价于 rect.x。yMinNumber矩形 y 轴上的最小值。xMaxNumber矩形 x 轴上的最大值。yMaxNumber矩形 y 轴上的最大值。centerVec2矩形的中心点。originVec2矩形的 x 和 y 坐标。sizeSize矩形的大小。
方法
constructorRect类的构造函数。fromMinMax根据指定 2 个坐标创建出一个矩形区域。clone克隆一个新的 Rect。equals是否等于指定的矩形。lerp线性插值intersects当前矩形与指定矩形是否相交。intersection返回 2 个矩形重叠的部分。contains当前矩形是否包含指定坐标点。containsRect当前矩形是否包含指定矩形。union返回一个包含当前矩形和指定矩形的最小矩形。transformMat4使用 mat4 对矩形进行矩阵转换。toString转换为方便阅读的字符串set从其它对象把所有属性复制到当前对象。
Details
属性(properties)
x
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/rect.ts:77 |
y
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/rect.ts:81 |
width
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/rect.ts:85 |
height
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/rect.ts:89 |
xMin
矩形 x 轴上的最小值,等价于 rect.x。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/rect.ts:329 |
yMin
矩形 y 轴上的最小值。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/rect.ts:343 |
xMax
矩形 x 轴上的最大值。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/rect.ts:358 |
yMax
矩形 y 轴上的最大值。
| meta | description |
|---|---|
| 类型 | Number |
| 定义于 | cocos2d/core/value-types/rect.ts:371 |
center
矩形的中心点。
| meta | description |
|---|---|
| 类型 | Vec2 |
| 定义于 | cocos2d/core/value-types/rect.ts:384 |
origin
矩形的 x 和 y 坐标。
| meta | description |
|---|---|
| 类型 | Vec2 |
| 定义于 | cocos2d/core/value-types/rect.ts:398 |
size
矩形的大小。
| meta | description |
|---|---|
| 类型 | Size |
| 定义于 | cocos2d/core/value-types/rect.ts:411 |
方法
constructor
Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/rect.ts:42 |
参数列表
fromMinMax
根据指定 2 个坐标创建出一个矩形区域。
| meta | description |
|---|---|
| 返回 | Rect |
| 定义于 | cocos2d/core/value-types/rect.ts:57 |
参数列表
示例
cc.Rect.fromMinMax(cc.v2(10, 10), cc.v2(20, 20)); // Rect {x: 10, y: 10, width: 10, height: 10};
clone
克隆一个新的 Rect。
| meta | description |
|---|---|
| 返回 | Rect |
| 定义于 | cocos2d/core/value-types/rect.ts:108 |
示例
var a = new cc.Rect(0, 0, 10, 10);
a.clone();// Rect {x: 0, y: 0, width: 10, height: 10}
equals
是否等于指定的矩形。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/rect.ts:121 |
参数列表
otherRect
示例
var a = new cc.Rect(0, 0, 10, 10);
var b = new cc.Rect(0, 0, 10, 10);
a.equals(b);// true;
lerp
线性插值
| meta | description |
|---|---|
| 返回 | Rect |
| 定义于 | cocos2d/core/value-types/rect.ts:140 |
参数列表
示例
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
当前矩形与指定矩形是否相交。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/rect.ts:179 |
参数列表
rectRect
示例
var a = new cc.Rect(0, 0, 10, 10);
var b = new cc.Rect(0, 0, 20, 20);
a.intersects(b);// true
intersection
返回 2 个矩形重叠的部分。
| meta | description |
|---|---|
| 返回 | Rect |
| 定义于 | cocos2d/core/value-types/rect.ts:198 |
参数列表
示例
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
当前矩形是否包含指定坐标点。 Returns true if the point inside this rectangle.
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/rect.ts:221 |
参数列表
pointVec2
示例
var a = new cc.Rect(0, 0, 10, 10);
var b = new cc.Vec2(0, 5);
a.contains(b);// true
containsRect
当前矩形是否包含指定矩形。
| meta | description |
|---|---|
| 返回 | Boolean |
| 定义于 | cocos2d/core/value-types/rect.ts:240 |
参数列表
rectRect
示例
var a = new cc.Rect(0, 0, 20, 20);
var b = new cc.Rect(0, 0, 10, 10);
a.containsRect(b);// true
union
返回一个包含当前矩形和指定矩形的最小矩形。
| meta | description |
|---|---|
| 返回 | Rect |
| 定义于 | cocos2d/core/value-types/rect.ts:258 |
参数列表
示例
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
使用 mat4 对矩形进行矩阵转换。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/rect.ts:281 |
参数列表
toString
转换为方便阅读的字符串
| meta | description |
|---|---|
| 返回 | String |
| 定义于 | cocos2d/core/value-types/rect.ts:315 |
示例
var a = new cc.Rect(0, 0, 10, 10);
a.toString();// "(0.00, 0.00, 10.00, 10.00)";
set
从其它对象把所有属性复制到当前对象。
| meta | description |
|---|---|
| 定义于 | cocos2d/core/value-types/value-type.ts:80 |
参数列表
sourceValueType the source to copy