~1 min read

Keyboard movement

Move a sprite with WASD or arrow keys, polling input each frame with delta-time velocity.

Keyboard movement Phaser 4 · sandboxed

Notes

  • Click the playground first so the iframe receives keyboard focus.
  • createCursorKeys() gives you cursors.left/right/up/down/space/shift ready to poll.
  • addKeys({ up: 'W', ... }) lets you offer WASD parity with a one-liner.
  • Movement is speed * (delta / 1000) — pixels per second, framerate-independent. See The Game Loop.
  • Polling style fits continuous movement; events fit discrete actions (jump, fire). See Input.