Entity

a single physical object in the physics simulation

.applyImpulse( power, degrees )

powerof impulse

degreesdirection of force. 0 is up, 90 is right, etc.

Apply an instantanious force on this Entity.
With this and all functions that take degrees, you can also provide
a vector.
entity.applyImpulse(10, 45); // 45 degree angle
entity.applyImpulse(10, 1, -1); // the vector x=1 y=-1}

.borderColor( [value] )

valuecss color string

returncss color string

get or set entity's border color

.borderWidth( [value] )

valuenumber

returnnumber

get or set entity's border width.
Set to 0 to not show a border.

.canvasPosition( )

return{x,y}

Get the Entity position in pixels. Useful for custom
rendering. Unlike position the result
is relative to the World's scale and camera position.

.clearForce( name )

Stop the force with the given name.

.clearVelocity( name )

Stop the constant velocity with the given name.

.color( [value] )

valuecss color string

returncss color string

get or set entity's color

.destroy( )

destroy this entity and remove it from the world

.draw( [value] )

valuefunction

returnfunction

get or set the draw function for this entity

.friction( [value] )

valuenumber

returnnumber

get or set entity friction

.image( [value] )

valuestring

returnstring

get or set entity image

.imageOffsetX( [value] )

valuenumber

returnnumber

get or set entity image offset in the x direction

.imageOffsetY( [value] )

valuenumber

returnnumber

get or set entity image offset in the y direction

.imageStretchToFit( [value] )

valueboolean

returnboolean

set to true to stretch image to entity size

.maxVelocityX( [value] )

valuenumber

returnnumber

get or set entity max velocity left or right

.maxVelocityY( [value] )

valuenumber

returnnumber

get or set entity max velocity up or down

.name( [value] )

returnentity name

get or set entity name

.onFinishContact( callback )

callbackfunction( entity )

entitythat contact ended with

thisthis Entity

Handle end of contact with another entity.

.onImpact( callback )

callbackfunction( entity, normalForce, tangentialForce )

entitycollided with

normalForceforce of two entities colliding

tangentialForceforce of two entities "rubbing" up against each other

thisthis Entity

Handle impact with another entity.

.onKeydown( callback )

callbackfunction( e )

ekeydown event

thisthis Entity

Handle keydown event for this entity.

.onKeyup( callback )

callbackfunction( e )

ekeyup event

thisthis Entity

Handle keyup event for this entity.

.onRender( callback )

callbackfunction( context )

contextcanvas context for rendering

thisEntity

Add an onRender callback to this Entity
Multiple onRender callbacks can be added, and they can be removed
with world.unbindOnRender.

.onStartContact( callback )

callbackfunction( entity )

entitythat contact started with

thisthis Entity

Handle start of contact with another entity.

.onTick( callback )

callbackfunction()

thisEntity

Add an onTick callback to this Entity
Ticks are periodic events that happen independant of rendering.
You can use ticks as your "game loop". The default tick frequency
is 50 milliseconds, and it can be set as an option when creating
the world.
Multiple onTick callbacks can be added, and they can be removed
with world.unbindOnTick.

.position( [value] )

value{x,y}

return{x,y}

get or set entity position

.restitution( [value] )

valuenumber

returnnumber

get or set entity restitution (bounciness)

.rotation( [value] )

valuedegrees

returndegrees

get or set entity rotation

.setForce( name, power, degrees )

nameof force

powerof force

degreesdirection of force

Apply a constant force on this Entity. Can be removed later
using clearForce.

.setVelocity( name, power, degrees )

nameof velocity

powerof velocity

degreesdirection of velocity

Continuously override velocity of this Entity. Can be removed later
using clearVelocity. Usually you probably want setForce or applyImpulse.

.sprite( x, y )

Set the entity's image to the sprite at x, y on the sprite sheet.
Used only on entities with spriteSheet:true

.spriteHeight( [value] )

valuenumber

returnnumber

get or set height of a sprite on the sprite sheet

.spriteSheet( [value] )

valueboolean

returnboolean

get or set if this entity's image is a sprite sheet

.spriteWidth( [value] )

valuenumber

returnnumber

get or set width of a sprite on the sprite sheet

World

contains a single self-contained physics simulation

.camera( [value] )

value{x,y}

return{x,y}

get or set position of camera

.canvasPositionAt( x, y )

return{x,y}

Get a canvas position for a corresponding world position. Useful
for custom rendering in onRender. Respects world scale and camera position.

Dollar Properties

You can provide options that start with a $ like this:
var ball = world.createEntity({color: "red", $customValue: 15});
These are passed onto the resulting entity as they are:
ball.$customValue === 15
This allows you to provide your own custom methods and properties.

.find( x1, y1, x2, y2 )

.gravity( [value] )

value:{x,y}

return:{x,y}

get or set the world's gravity

.onRender( callback )

callbackfunction( context )

contextcanvas context for rendering

thisWorld

Add an onRender callback to the World
This is useful for custom rendering. For example, to draw text
on every frame:
world.onRender(function(ctx) {
ctx.fillText("Score: " + score, 10, 10);
});
This callback occurs after all entities have been rendered on the
frame.
Multiple onRender callbacks can be added, and they can be removed
with unbindOnRender.

.onTick( callback )

callbackfunction()

thisWorld

Add an onTick callback to the World
Ticks are periodic events that happen independant of rendering.
You can use ticks as your "game loop". The default tick frequency
is 50 milliseconds, and it can be set as an option when creating
the world.
Multiple onTick callbacks can be added, and they can be removed
with unbindOnTick.

.scale( [value] )

valuenumber

returnnumber

get or set the scale for rendering in pixels / meter

.unbindOnRender( callback )

callbackcallback

If the provided function is currently an onRender callback for this
World, it is removed.

.unbindOnTick( callback )

callbackcallback

If the provided function is currently an onTick callback for this
World, it is removed.