API Docs for: 0.7.1
Show:

# Shape Class

Base class for shapes.

## Constructor

### `Shape`

(
• `[options]`
)

#### Parameters:

• `[options]` Object optional
• `[position]` Array optional
• `[angle=0]` Number optional
• `[collisionGroup=1]` Number optional
• `[collisionMask=1]` Number optional
• `[sensor=false]` Boolean optional
• `[collisionResponse=true]` Boolean optional
• `[type=0]` Object optional

## Methods

### `computeAABB`

(
• `out`
• `position`
• `angle`
)

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

#### Parameters:

• `out` AABB

The resulting AABB.

• `position` Array

World position of the shape.

• `angle` Number

World angle of the shape.

### `computeMomentOfInertia`

(
• `mass`
)
Number

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.

### `raycast`

(
• `result`
• `ray`
• `position`
• `angle`
)

Perform raycasting on this shape.

#### Parameters:

• `result` RayResult

Where to store the resulting data.

• `ray` Ray

The Ray that you want to use for raycasting.

• `position` Array

World position of the shape (the .position property will be ignored).

• `angle` Number

World angle of the shape (the .angle property will be ignored).

### `updateArea`

()

Update the .area property of the shape.

### `updateBoundingRadius`

() Number

Returns the bounding circle radius of this shape.

Number:

## Properties

### `angle`

Number

Body-local angle of the shape.

### `area`

Number

Area of this shape.

### `body`

Body

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

### `boundingRadius`

Number

Bounding circle radius of this shape

Number static

Number static

Number static

### `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.
enemyShape  .collisionMask = PLAYER | GROUND;
groundShape .collisionMask = PLAYER | ENEMY;
``````
``````// How collision check is done
// 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.

Number static

Number static

### `id`

Number

Shape object identifier.

Number static

### `material`

Material

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

Number static

Number static

### `position`

Array

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`

Number

The type of the shape. One of: