Input
Keyboard, pointer (mouse + touch), and gamepad — and how Phaser routes events to game objects.
Phaser unifies keyboard, pointer (mouse + touch), and gamepad behind a single input manager exposed as this.input.
Polling vs. events
Two valid styles:
// Event style — react to a single transition.
this.input.keyboard!.on('keydown-SPACE', () => this.jump());
// Polling style — check state every frame in update().
const cursors = this.input.keyboard!.createCursorKeys();
update() {
if (cursors.left.isDown) this.player.x -= 4;
}
Polling fits continuous actions (movement); events fit discrete actions (jump, fire, menu select).
Pointer
this.input.on('pointerdown', (pointer) => {
const world = this.cameras.main.getWorldPoint(pointer.x, pointer.y);
this.spawnAt(world.x, world.y);
});
The pointer always reports screen coordinates. Use camera.getWorldPoint to translate.
Per-object interactivity
For “click this sprite” semantics, opt the object in:
button.setInteractive({ useHandCursor: true });
button.on('pointerdown', () => this.scene.start('Game'));
Phaser tests the object’s bounds (rectangle by default; pixel-perfect if requested) and only fires events when the pointer actually intersects.
Gamepad
Gamepad support is off by default — enable it in the game config:
input: { gamepad: true }
Then read this.input.gamepad!.pad1?.buttons[0].pressed etc. in update.