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.


Back to top


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

The speed of motion in pixels per second.


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.


Crafty.e("2D, Color, Fourway")
   .attr({x: 100, y: 100, w: 50, h:50})
   .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.