All examples · Input

Keyboard and pointer

What this example shows

Drive the sprite with the arrow keys or WASD through useKeyboard().isDown. The three bars show the three places a sprite gets its pointer events. The left one has them in createSprite's options. The middle one gets them from listen() right after it is created, with no update involved. The red one starts with none: walk the player into it, and a useUpdate that notices calls listen() once.

listen() works anywhere; the update is only there because touching the player is something you have to check every frame. Click the canvas first so it takes keyboard focus.

Starting