Rect 类型
继承于 ValueType
通过位置和宽高定义的 2D 矩形。
索引
属性(properties)
- x- Number
- y- Number
- width- Number
- height- Number
- xMin- Number矩形 x 轴上的最小值,等价于 rect.x。
- yMin- Number矩形 y 轴上的最小值。
- xMax- Number矩形 x 轴上的最大值。
- yMax- Number矩形 y 轴上的最大值。
- center- Vec2矩形的中心点。
- origin- Vec2矩形的 x 和 y 坐标。
- size- Size矩形的大小。
方法
- 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.js:67 | 
y
| meta | description | 
|---|---|
| 类型 | Number | 
| 定义于 | cocos2d/core/value-types/rect.js:70 | 
width
| meta | description | 
|---|---|
| 类型 | Number | 
| 定义于 | cocos2d/core/value-types/rect.js:73 | 
height
| meta | description | 
|---|---|
| 类型 | Number | 
| 定义于 | cocos2d/core/value-types/rect.js:76 | 
xMin
矩形 x 轴上的最小值,等价于 rect.x。
| meta | description | 
|---|---|
| 类型 | Number | 
| 定义于 | cocos2d/core/value-types/rect.js:322 | 
yMin
矩形 y 轴上的最小值。
| meta | description | 
|---|---|
| 类型 | Number | 
| 定义于 | cocos2d/core/value-types/rect.js:336 | 
xMax
矩形 x 轴上的最大值。
| meta | description | 
|---|---|
| 类型 | Number | 
| 定义于 | cocos2d/core/value-types/rect.js:350 | 
yMax
矩形 y 轴上的最大值。
| meta | description | 
|---|---|
| 类型 | Number | 
| 定义于 | cocos2d/core/value-types/rect.js:361 | 
center
矩形的中心点。
| meta | description | 
|---|---|
| 类型 | Vec2 | 
| 定义于 | cocos2d/core/value-types/rect.js:372 | 
origin
矩形的 x 和 y 坐标。
| meta | description | 
|---|---|
| 类型 | Vec2 | 
| 定义于 | cocos2d/core/value-types/rect.js:388 | 
size
矩形的大小。
| meta | description | 
|---|---|
| 类型 | Size | 
| 定义于 | cocos2d/core/value-types/rect.js:403 | 
方法
constructor
Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。
| meta | description | 
|---|---|
| 定义于 | cocos2d/core/value-types/rect.js:39 | 
参数列表
fromMinMax
根据指定 2 个坐标创建出一个矩形区域。
| meta | description | 
|---|---|
| 返回 | Rect | 
| 定义于 | cocos2d/core/value-types/rect.js:80 | 
参数列表
示例
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.js:102 | 
示例
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.js:115 | 
参数列表
- 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.js:134 | 
参数列表
示例
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.js:172 | 
参数列表
- 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.js:191 | 
参数列表
示例
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.js:214 | 
参数列表
- 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.js:233 | 
参数列表
- 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.js:251 | 
参数列表
示例
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.js:274 | 
参数列表
toString
转换为方便阅读的字符串
| meta | description | 
|---|---|
| 返回 | String | 
| 定义于 | cocos2d/core/value-types/rect.js:308 | 
示例
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.js:84 | 
参数列表
- sourceValueType the source to copy
