Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Body

Hierarchy

  • Body

Index

Constructors

constructor

  • Constructs a new physics body associated with an actor

    Parameters

    Returns Body

Properties

Private _totalMtv

_totalMtv: Vector = Vector.Zero.clone()

acc

acc: Vector = new ex.Vector(0, 0)

The curret acceleration vector (ax, ay) of the actor in pixels/second/second. An acceleration pointing down such as (0, 100) may be useful to simulate a gravitational effect.

actor

actor: Actor

collisionArea

collisionArea: ICollisionArea = null

[ICollisionArea|Collision area] of this physics body, defines the shape for rigid body collision

friction

friction: number = 0.99

The coefficient of friction on this actor

mass

mass: number = 1

The current mass of the actor, mass can be thought of as the resistance to acceleration.

moi

moi: number = 1000

The current moment of inertia, moi can be thought of as the resistance to rotation.

motion

motion: number = 10

The current "motion" of the actor, used to calculated sleep in the physics simulation

oldPos

oldPos: Vector = new ex.Vector(0, 0)

The position of the actor last frame (x, y) in pixels

oldVel

oldVel: Vector = new ex.Vector(0, 0)

The velocity of the actor last frame (vx, vy) in pixels/second

pos

pos: Vector = new ex.Vector(0, 0)

The (x, y) position of the actor this will be in the middle of the actor if the [[anchor]] is set to (0.5, 0.5) which is default. If you want the (x, y) position to be the top left of the actor specify an anchor of (0, 0).

restitution

restitution: number = 0.2

The coefficient of restitution of this actor, represents the amount of energy preserved after collision

rotation

rotation: number = 0

The rotation of the actor in radians

rx

rx: number = 0

The rotational velocity of the actor in radians/second

torque

torque: number = 0

The current torque applied to the actor

vel

vel: Vector = new ex.Vector(0, 0)

The current velocity vector (vx, vy) of the actor in pixels/second

Methods

addMtv

  • Add minimum translation vectors accumulated during the current frame to resolve collisions.

    Parameters

    Returns void

applyMtv

  • applyMtv(): void
  • Applies the accumulated translation vectors to the actors position

    Returns void

debugDraw

  • debugDraw(ctx: CanvasRenderingContext2D): void
  • Parameters

    • ctx: CanvasRenderingContext2D

    Returns void

getBounds

  • Returns the body's BoundingBox calculated for this instant in world space.

    Returns BoundingBox

getRelativeBounds

  • Returns the actor's BoundingBox relative to the actors position.

    Returns BoundingBox

update

  • update(): void
  • Updates the collision area geometry and internal caches

    Returns void

useBoxCollision

  • useBoxCollision(center?: Vector): void
  • Sets up a box collision area based on the current bounds of the associated actor of this physics body.

    By default, the box is center is at (0, 0) which means it is centered around the actors anchor.

    Parameters

    • Default value center: Vector = ex.Vector.Zero.clone()

    Returns void

useCircleCollision

  • useCircleCollision(radius?: number, center?: Vector): void
  • Sets up a circle collision area with a specified radius in pixels.

    By default, the box is center is at (0, 0) which means it is centered around the actors anchor.

    Parameters

    • Optional radius: number
    • Default value center: Vector = ex.Vector.Zero.clone()

    Returns void

useEdgeCollision

  • Sets up an edge collision with a start point and an end point relative to the anchor of the associated actor of this physics body.

    By default, the box is center is at (0, 0) which means it is centered around the actors anchor.

    Parameters

    Returns void

usePolygonCollision

  • usePolygonCollision(points: Vector[], center?: Vector): void
  • Sets up a polygon collision area based on a list of of points relative to the anchor of the associated actor of this physics body.

    Only convex polygon definitions are supported.

    By default, the box is center is at (0, 0) which means it is centered around the actors anchor.

    Parameters

    • points: Vector[]
    • Default value center: Vector = ex.Vector.Zero.clone()

    Returns void