Class ShapeAbstract

Base class for shapes. Not to be used directly.

Hierarchy

Constructors

  • Constructor for a Shape

    Parameters

    Returns Shape

Properties

angle: number

Body-local angle of the shape.

area: number = 0

Area of this shape.

body: null | Body = null

The body this shape is attached to. A shape can only be attached to a single body.

boundingRadius: number = 0

Bounding circle radius of this shape

collisionGroup: number

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;

Example

// How collision check is done
if(shapeA.collisionGroup & shapeB.collisionMask)!=0 && (shapeB.collisionGroup & shapeA.collisionMask)!=0){
// The shapes will collide
}
collisionMask: number

Collision mask of this shape. See .collisionGroup.

collisionResponse: boolean

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

Shape object identifier

material: null | Material

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

position: Vec2 = ...

Body-local position of the shape.

sensor: boolean

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.

type: 2 | 1 | 4 | 8 | 16 | 32 | 64 | 128
BOX: 32 = ...

Box shape type

CAPSULE: 64 = ...

Capsule shape type

CIRCLE: 1 = ...

Circle shape type

CONVEX: 8 = ...

Convex shape type

HEIGHTFIELD: 128 = ...

Heightfield shape type

LINE: 16 = ...

Line shape type

PARTICLE: 2 = ...

Particle shape type

PLANE: 4 = ...

Plane shape type

idCounter: number = 0

ID counter for shapes

Methods

  • Compute the world axis-aligned bounding box (AABB) of this shape.

    Parameters

    • Optional out: AABB

      The resulting AABB.

    • Optional position: Vec2

      World position of the shape.

    • Optional angle: number

      World angle of the shape.

    Returns void

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

    Returns number

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

  • Test if a point is inside this shape.

    Parameters

    Returns boolean

    whether a point is inside this shape

  • Perform raycasting on this shape.

    Parameters

    Returns void

  • Update the .area property of the shape.

    Returns void

  • Updates the bounding circle radius of this shape.

    Returns void

  • Transform a world point to local shape space (assumed the shape is transformed by both itself and the body).

    Parameters

    Returns Vec2