API Docs for: v0.1.0
Show:

PhysicsTarget Class

Physics mixin. This will add physics capabilities to the class it mixes into.

Constructor

PhysicsTarget

()

Methods

disablePhysics

() Mixed chainable async

Disbales physics for this sprite

Returns:

Mixed:

Returns itself.

disablePhysics

() Mixed chainable async

Reindexes the collisions for this sprite, useful when moving the sprite a great deal (like to a new world)

Returns:

Mixed:

Returns itself.

enablePhysics

(
  • system
)
Mixed chainable async

Enables physics for this sprite

Parameters:

Returns:

Mixed:

Returns itself.

setMass

(
  • mass
)
Mixed chainable

Sets the mass of this sprite

Parameters:

  • mass Number

    The new mass of the object

Returns:

Mixed:

Returns itself.

setPosition

(
  • x
  • y
)
Mixed chainable

Sets the position of this sprite

Parameters:

  • x Number
  • y Number

Returns:

Mixed:

Returns itself.

setRotation

(
  • rotation
)
Mixed chainable

Sets the rotation of this sprite

Parameters:

  • rotation Number

    The new rotation of the object in radians

Returns:

Mixed:

Returns itself.

setVelocity

(
  • velocity
)
Mixed chainable

Sets the velocity of this sprite

Parameters:

  • velocity Vector

    The new velocity of the object

Returns:

Mixed:

Returns itself.

Properties

_phys

Object private

The physics namespace that all physics properties go into. Those properties are:

  • system {PhysicsSystem} PhysicsSystem that this object is a part of.
  • active {Boolean} Whether or not this target is actively having physics simulated.

Default: {}

inertia

Number

The moment of inertia of this object, only set this before enabling physics (has no effect after enabling)

Default: 0

mass

Number

The mass of this object, please use setMass to set this value

Default: 0

Events

collision

On Collision Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for

Event Payload:

  • obj Sprite

    Colliding sprite

  • vec Vector

    Collision vector (for sensors this is normalized)

  • colShape cp.Shape

    The colliding physics shape

  • myShape cp.Shape

    Your physics shape that caused the collision

separate

On Seperate Event called when this sprite collides into another, or is being collided into by another. By default if something collides with a collectable sprite we destroy the collectable and if we collide with a solid tile we kill our velocity. This method will emit a 'collision' event that you can listen for

Event Payload:

  • obj Sprite

    Colliding sprite

  • colShape cp.Shape

    The colliding physics shape

  • myShape cp.Shape

    Your physics shape that caused the collision