API Docs for: v0.1.1
Show:

PhysicsTarget Class

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

Constructor

PhysicsTarget

()

Methods

disablePhysics

(
  • callback
)
Mixed chainable async

Disbales physics for this sprite

Parameters:

  • callback Function

    The callback function to call after physics have been disabled

Returns:

Mixed:

Returns itself.

disablePhysics

(
  • callback
)
Mixed chainable async

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

Parameters:

  • callback Function

    The callback function to call after the sprite has been reindexed

Returns:

Mixed:

Returns itself.

enablePhysics

(
  • system
  • callback
)
Mixed chainable async

Enables physics for this sprite

Parameters:

  • system PhysicsSystem

    The system for the sprite to be in

  • callback Function

    The callback function to call after physics have been enabled

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 | Vector

    The x coord to set position to, if a Vector is passed the y param is ignored

  • y Number

    The y coord to set position to

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

(
  • x
  • y
)
Mixed chainable

Sets the velocity of this sprite

Parameters:

  • x Number | Vector

    The x coord to set the velocity to, if a Vector is passed the y param is ignored

  • y Number

    The y coord to set the velocity to

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: {}

_velocity

Vector private

The internal velocity value, used as a reusable vector for the setVelocity function. Setting this directly has no effect.

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