craftyjs.github.com

Fourway

Move an entity in four directions by using the arrow keys or W, A, S, D.

Back to top

.fourway

public this .fourway(Number speed)

speed
Amount of pixels to move the entity whilst a key is down

Constructor to initialize the speed. Component will listen for key events and move the entity appropriately. This includes Up Arrow, Right Arrow, Down Arrow, Left Arrow as well as W, A, S, D.

When direction changes a NewDirection event is triggered with an object detailing the new direction: {x: x_movement, y: y_movement} When entity has moved on either x- or y-axis a Moved event is triggered with an object specifying the old position {x: old_x, y: old_y}

The key presses will move the entity in that direction by the speed passed in the argument.

See Also