Line Class
线状,线状沿着X轴,跨度为 [-length/2, 0] 到 [length/2,0]
构造器
项目索引
Methods
computeMomentOfInertia
(
Number
-
mass
返回围绕给定了质量的刚体的Z轴的转动惯量. 参见维基百科.
参数:
-
massNumber
Returns:
Number:
如果惯性是无穷的或这一物体不可能旋转,则返回0
updateArea
()
更新 .area 属性
updateBoundingRadius
()
Number
返回这个形状的包围半径
Returns:
Number:
Properties
angle
Number
基于刚体的角度
area
Number
形状的面积
boundingRadius
Number
形状的包围半径
collisionGroup
Number
形状所属的碰撞分组(位掩码). 参见 这一教程.
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
碰撞掩码,参见 .collisionGroup.
collisionResponse
Boolean
当与其他刚体碰撞时是否产生碰撞作用力。需要注意的是,碰撞仍会产生,但会被禁用。即:该刚体会穿过其他刚体,但仍然会触发碰撞等事件。
id
Number
形状的唯一标志符
length
Number
这条线的长度
Default: 1
position
Array
基于刚体的位置
sensor
Boolean
如果你希望此形状为传感器,则设置为true。传感器不会产生碰撞,但仍会上报碰撞事件。它在你想在不产生碰撞的情况下知道这一形状是否与其他形状重叠的情况下很实用
