Class Circle

Circle shape class.

Example

var body = new Body({ mass: 1 });
var circleShape = new Circle({
radius: 1
});
body.addShape(circleShape);

Hierarchy

Constructors

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.

radius: number

The radius of the circle.

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

    • out: AABB

      The resulting AABB.

    • position: Vec2

      World position of the shape.

    Returns void

  • 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