Fourway Component

Move an entity in four directions by using the Up Arrow, Left Arrow, Down Arrow, Right Arrow keys or W, A, S, D.

This component is a thin wrapper around the Multiway component and sets the appropriate key bindings. It is a well suited for games with a top-down (birds-eye) perspective.

Methods

Back to top

.fourway()

public this .fourway([Number speed[, Object options]])
speed

The speed of motion in pixels per second.

options

A dictionary of options passed through to the underlying Multiway component

Initialize the component with the given speed and options. See the Multiway component for available options.

Example

Crafty.e("2D, Color, Fourway")
   .attr({x: 100, y: 100, w: 50, h:50})
   .color("green")
   .fourway(100, {normalize:true});

Create a green square controlled by the arrow keys and WASD, with diagonal movement normalized to the given speed.

The speed is in units of pixels per second.