craftyjs.github.com

Multiway

Used to bind keys to directions and have the entity move accordingly

Events

NewDirection [New direction: { x:Number, y:Number }]
triggered when direction changes
Moved [Old position: { x:Number, y:Number }]
triggered on movement on either x or y axis. If the entity has moved on both axes for diagonal movement the event is triggered twice
Back to top

.multiway

public this .multiway([Number speed,] Object keyBindings )

speed
Amount of pixels to move the entity whilst a key is down
keyBindings
What keys should make the entity go in which direction. Direction is specified in degrees

Constructor to initialize the speed and keyBindings. Component will listen to key events and move the entity appropriately.

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}

Example

this.multiway(3, {UP_ARROW: -90, DOWN_ARROW: 90, RIGHT_ARROW: 0, LEFT_ARROW: 180});
this.multiway({x:3,y:1.5}, {UP_ARROW: -90, DOWN_ARROW: 90, RIGHT_ARROW: 0, LEFT_ARROW: 180});
this.multiway({W: -90, S: 90, D: 0, A: 180});
Back to top

.enableControl

public this .enableControl()

Enable the component to listen to key events.

Example

this.enableControl();
Back to top

.disableControl

public this .disableControl()

Disable the component to listen to key events.

Example

this.disableControl();