• Rect 类型
    • 索引
      • 属性(properties)
      • 方法
  • Details
    • 属性(properties)
      • x
      • y
      • width
      • height
      • xMin
      • yMin
      • xMax
      • yMax
      • center
      • origin
      • size
        • 参数列表
      • fromMinMax
        • 参数列表
      • 示例
      • clone
      • 示例
      • equals
        • 参数列表
      • 示例
      • lerp
        • 参数列表
      • 示例
      • intersects
        • 参数列表
      • 示例
      • intersection
        • 参数列表
      • 示例
      • contains
        • 参数列表
      • 示例
      • containsRect
        • 参数列表
      • 示例
      • union
        • 参数列表
      • 示例
      • transformMat4
        • 参数列表
      • toString
      • 示例
      • set
        • 参数列表

    Rect 类型

    继承于 ValueType

    模块: cc父模块: cc

    通过位置和宽高定义的 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 矩形的大小。
    方法
    • constructor Rect类的构造函数。
    • fromMinMax 根据指定 2 个坐标创建出一个矩形区域。
    • clone 克隆一个新的 Rect。
    • equals 是否等于指定的矩形。
    • lerp 线性插值
    • intersects 当前矩形与指定矩形是否相交。
    • intersection 返回 2 个矩形重叠的部分。
    • contains 当前矩形是否包含指定坐标点。
    • containsRect 当前矩形是否包含指定矩形。
    • union 返回一个包含当前矩形和指定矩形的最小矩形。
    • transformMat4 使用 mat4 对矩形进行矩阵转换。
    • toString 转换为方便阅读的字符串
    • set 从其它对象把所有属性复制到当前对象。

    Details

    属性(properties)

    x

    metadescription
    类型Number
    定义于cocos2d/core/value-types/rect.js:67
    y

    metadescription
    类型Number
    定义于cocos2d/core/value-types/rect.js:70
    width

    metadescription
    类型Number
    定义于cocos2d/core/value-types/rect.js:73
    height

    metadescription
    类型Number
    定义于cocos2d/core/value-types/rect.js:76
    xMin
    矩形 x 轴上的最小值,等价于 rect.x。
    metadescription
    类型Number
    定义于cocos2d/core/value-types/rect.js:321
    yMin
    矩形 y 轴上的最小值。
    metadescription
    类型Number
    定义于cocos2d/core/value-types/rect.js:335
    xMax
    矩形 x 轴上的最大值。
    metadescription
    类型Number
    定义于cocos2d/core/value-types/rect.js:349
    yMax
    矩形 y 轴上的最大值。
    metadescription
    类型Number
    定义于cocos2d/core/value-types/rect.js:360
    center
    矩形的中心点。
    metadescription
    类型Vec2
    定义于cocos2d/core/value-types/rect.js:371
    origin
    矩形的 x 和 y 坐标。
    metadescription
    类型Vec2
    定义于cocos2d/core/value-types/rect.js:387
    size
    矩形的大小。
    metadescription
    类型Size
    定义于cocos2d/core/value-types/rect.js:402



    #### 方法



    ##### constructor


    Rect类的构造函数。可以通过 cc.rect 简便方法进行创建。

    metadescription
    定义于cocos2d/core/value-types/rect.js:39
    参数列表
    • x Number
    • y Number
    • w Number
    • h Number
    fromMinMax

    根据指定 2 个坐标创建出一个矩形区域。

    metadescription
    返回Rect
    定义于cocos2d/core/value-types/rect.js:80
    参数列表
    • v1 Vec2
    • v2 Vec2
    示例
    1. cc.Rect.fromMinMax(cc.v2(10, 10), cc.v2(20, 20)); // Rect {x: 10, y: 10, width: 10, height: 10};
    clone

    克隆一个新的 Rect。

    metadescription
    返回Rect
    定义于cocos2d/core/value-types/rect.js:102
    示例
    1. var a = new cc.Rect(0, 0, 10, 10);
    2. a.clone();// Rect {x: 0, y: 0, width: 10, height: 10}
    equals

    是否等于指定的矩形。

    metadescription
    返回Boolean
    定义于cocos2d/core/value-types/rect.js:115
    参数列表
    • other Rect
    示例
    1. var a = new cc.Rect(0, 0, 10, 10);
    2. var b = new cc.Rect(0, 0, 10, 10);
    3. a.equals(b);// true;
    lerp

    线性插值

    metadescription
    返回Rect
    定义于cocos2d/core/value-types/rect.js:134
    参数列表
    • to Rect
    • ratio Number the interpolation coefficient.
    • out Rect optional, the receiving vector.
    示例
    1. var a = new cc.Rect(0, 0, 10, 10);
    2. var b = new cc.Rect(50, 50, 100, 100);
    3. update (dt) {
    4. // method 1;
    5. var c = a.lerp(b, dt * 0.1);
    6. // method 2;
    7. a.lerp(b, dt * 0.1, c);
    8. }
    intersects

    当前矩形与指定矩形是否相交。

    metadescription
    返回Boolean
    定义于cocos2d/core/value-types/rect.js:172
    参数列表
    • rect Rect
    示例
    1. var a = new cc.Rect(0, 0, 10, 10);
    2. var b = new cc.Rect(0, 0, 20, 20);
    3. a.intersects(b);// true
    intersection

    返回 2 个矩形重叠的部分。

    metadescription
    返回Rect
    定义于cocos2d/core/value-types/rect.js:191
    参数列表
    • out Rect Stores the result
    • rectB Rect
    示例
    1. var a = new cc.Rect(0, 10, 20, 20);
    2. var b = new cc.Rect(0, 10, 10, 10);
    3. var intersection = new cc.Rect();
    4. a.intersection(intersection, b); // intersection {x: 0, y: 10, width: 10, height: 10};
    contains

    当前矩形是否包含指定坐标点。Returns true if the point inside this rectangle.

    metadescription
    返回Boolean
    定义于cocos2d/core/value-types/rect.js:214
    参数列表
    • point Vec2
    示例
    1. var a = new cc.Rect(0, 0, 10, 10);
    2. var b = new cc.Vec2(0, 5);
    3. a.contains(b);// true
    containsRect

    当前矩形是否包含指定矩形。

    metadescription
    返回Boolean
    定义于cocos2d/core/value-types/rect.js:233
    参数列表
    • rect Rect
    示例
    1. var a = new cc.Rect(0, 0, 20, 20);
    2. var b = new cc.Rect(0, 0, 10, 10);
    3. a.containsRect(b);// true
    union

    返回一个包含当前矩形和指定矩形的最小矩形。

    metadescription
    返回Rect
    定义于cocos2d/core/value-types/rect.js:251
    参数列表
    • out Rect Stores the result
    • rectB Rect
    示例
    1. var a = new cc.Rect(0, 10, 20, 20);
    2. var b = new cc.Rect(0, 10, 10, 10);
    3. var union = new cc.Rect();
    4. a.union(union, b); // union {x: 0, y: 10, width: 20, height: 20};
    transformMat4

    使用 mat4 对矩形进行矩阵转换。

    metadescription
    定义于cocos2d/core/value-types/rect.js:274
    参数列表
    • out Rect The output rect
    • mat Mat4 The matrix4
    toString

    转换为方便阅读的字符串

    metadescription
    返回String
    定义于cocos2d/core/value-types/rect.js:307
    示例
    1. var a = new cc.Rect(0, 0, 10, 10);
    2. a.toString();// "(0.00, 0.00, 10.00, 10.00)";
    set

    从其它对象把所有属性复制到当前对象。

    metadescription
    定义于cocos2d/core/value-types/value-type.js:84
    参数列表
    • source ValueType the source to copy