API Docs for: 0.7.1
Show:

Heightfield Class

Extends Shape

地形形状类。高度数据以数组给出。这些数据点分布均匀,距离为elementwidth。

构造器

Heightfield

(
  • [options]
)

参数:

  • [options] Object 可选

    (注意:这一参数将传入 Shape 的构造器)

    • [heights] Array 可选

      用于构造地形的y值数组。

    • [minValue] Number 可选

      数据中数据点的最小值。没有给出时将自动计算。

    • [maxValue] Number 可选

      数据中数据点的最大值。没有给出时将自动计算。

    • [elementWidth=0.1] Number 可选

      x方向数据点之间的间距

Example:

// Generate some height data (y-values).
        var heights = [];
        for(var i = 0; i < 1000; i++){
            var y = 0.5 * Math.cos(0.2 * i);
            heights.push(y);
        }
        
        // Create the heightfield shape
        var heightfieldShape = new Heightfield({
            heights: heights,
            elementWidth: 1 // Distance between the data points in X direction
        });
        var heightfieldBody = new Body();
        heightfieldBody.addShape(heightfieldShape);
        world.addBody(heightfieldBody);
        

Methods

computeAABB

(
  • out
  • position
  • angle
)

Inherited from Shape but overwritten in src/shapes/Heightfield.js:137

参数:

  • out AABB

    由此产生的AABB 包围盒

  • position Array
  • angle Number

computeMomentOfInertia

(
  • mass
)
Number

Inherited from Shape but overwritten in src/shapes/Heightfield.js:108

参数:

  • mass Number

Returns:

Number:

getLineSegment

(
  • start
  • end
  • i
)

获取地形中的线段

参数:

  • start Array

    存储生成的起始点的数组

  • end Array

    存储生成的终止点的数组

  • i Number

raycast

(
  • result
  • ray
  • position
  • angle
)

Inherited from Shape but overwritten in src/shapes/Heightfield.js:205

参数:

  • result RayResult
  • ray Ray
  • position Array
  • angle Number

updateArea

()

Inherited from Shape: src/shapes/Shape.js:215

更新 .area 属性

updateBoundingRadius

() Number

Inherited from Shape: src/shapes/Shape.js:208

更新形状的包围圆半径

Returns:

Number:

updateMaxMinValues

()

更新 .minValue 和 .maxValue属性

Properties

angle

Number

Inherited from Shape: src/shapes/Shape.js:36

基于刚体的角度

area

Number

Inherited from Shape: src/shapes/Shape.js:123

形状的面积

body

Body

Inherited from Shape: src/shapes/Shape.js:21

形状依附的刚体,一个形状只能依附在一个刚体上

boundingRadius

Number

Inherited from Shape: src/shapes/Shape.js:65

形状的包围半径

collisionGroup

Number

Inherited from Shape: src/shapes/Shape.js:72

形状所属的碰撞分组(位掩码). 参见 这一教程.

Example:

// Setup bits for each available group
                    var PLAYER = Math.pow(2,0),
                        ENEMY =  Math.pow(2,1),
                        GROUND = Math.pow(2,2)
                    
                    // 为形状设置分组
                    player1Shape.collisionGroup = PLAYER;
                    player2Shape.collisionGroup = PLAYER;
                    enemyShape  .collisionGroup = ENEMY;
                    groundShape .collisionGroup = GROUND;
                    
                    //为形状设置对应的碰撞分组,下例表明玩家(PLAYER) 只会和地面(GROUND)和敌人(ENEMY)碰撞,而不会与其他玩家碰撞
                    // Note that the players can collide with ground and enemies, but not with other players.
                    player1Shape.collisionMask = ENEMY | GROUND;
                    player2Shape.collisionMask = ENEMY | GROUND;
                    enemyShape  .collisionMask = PLAYER | GROUND;
                    groundShape .collisionMask = PLAYER | ENEMY;
                    
// How collision check is done
                    if(shapeA.collisionGroup & shapeB.collisionMask)!=0 && (shapeB.collisionGroup & shapeA.collisionMask)!=0){
                        // The shapes will collide
                    }
                    

collisionMask

Number

Inherited from Shape: src/shapes/Shape.js:109

碰撞掩码,参见 .collisionGroup.

collisionResponse

Boolean

Inherited from Shape: src/shapes/Shape.js:103

当与其他刚体碰撞时是否产生碰撞作用力。需要注意的是,碰撞仍会产生,但会被禁用。即:该刚体会穿过其他刚体,但仍然会触发碰撞等事件。

elementWidth

Number

每个元素的宽度

heights

Array

沿x轴展开的一组数值或高度值

id

Number

Inherited from Shape: src/shapes/Shape.js:58

形状的唯一标志符

material

Material

Inherited from Shape: src/shapes/Shape.js:116

用于碰撞的材质,如果这被设置为null, 在物理世界中将使用默认材质替代

maxValue

Number

高度值的最大值

minValue

Number

高度值的最小值

position

Array

Inherited from Shape: src/shapes/Shape.js:27

基于刚体的位置

sensor

Boolean

Inherited from Shape: src/shapes/Shape.js:130

如果你希望此形状为传感器,则设置为true。传感器不会产生碰撞,但仍会上报碰撞事件。它在你想在不产生碰撞的情况下知道这一形状是否与其他形状重叠的情况下很实用

type

Number

Inherited from Shape: src/shapes/Shape.js:42