API Docs for: 0.6.1
Show:

Line Class

Extends Shape
Defined in: src/shapes/Line.js:6

Line shape class. The line shape is along the x direction, and stretches from [-length/2, 0] to [length/2,0].

Constructor

Line

(
  • [length=1]
)

Parameters:

  • [length=1] Number optional

    The total length of the line

Methods

computeAABB

(
  • out
  • position
  • angle
)

Inherited from Shape but overwritten in src/shapes/Line.js:37

Parameters:

  • out AABB

    The resulting AABB.

  • position Array
  • angle Number

computeMomentOfInertia

(
  • mass
)
Number

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

Should return the moment of inertia around the Z axis of the body given the total mass. See Wikipedia's list of moments of inertia.

Parameters:

  • mass Number

Returns:

Number:

If the inertia is infinity or if the object simply isn't possible to rotate, return 0.

updateArea

()

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

Update the .area property of the shape.

updateBoundingRadius

() Number

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

Returns the bounding circle radius of this shape.

Returns:

Number:

Properties

area

Number

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

Area of this shape.

boundingRadius

Number

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

Bounding circle radius of this shape

collisionGroup

Number

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

Collision group that this shape belongs to (bit mask). See this tutorial.

Example:

// Setup bits for each available group
                    var PLAYER = Math.pow(2,0),
                        ENEMY =  Math.pow(2,1),
                        GROUND = Math.pow(2,2)
                    
                    // Put shapes into their groups
                    player1Shape.collisionGroup = PLAYER;
                    player2Shape.collisionGroup = PLAYER;
                    enemyShape  .collisionGroup = ENEMY;
                    groundShape .collisionGroup = GROUND;
                    
                    // Assign groups that each shape collide with.
                    // 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:78

Collision mask of this shape. See .collisionGroup.

collisionResponse

Boolean

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

Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled. That means that this shape will move through other body shapes, but it will still trigger contact events, etc.

id

Number

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

Shape object identifier.

length

Number

Length of this line

material

Material

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

Material to use in collisions for this Shape. If this is set to null, the world will use default material properties instead.

sensor

Boolean

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

Set to true if you want this shape to be a sensor. A sensor does not generate contacts, but it still reports contact events. This is good if you want to know if a shape is overlapping another shape, without them generating contacts.