Assemble3

Wiki

Detecting keys

To react to the keyboard, use the conditions of the Keyboard object.

The conditions

Condition True when
Key pressed The key is being held (every frame).
Key just pressed The key was pressed this frame (only once).
Key released The key was just let go.
Any key pressed Any key is being held.

When you create the condition, pick the key from the list or type its name (Left, Right, Up, Down, Space, Return, a…).

Example: move with the arrows

Conditions Actions
Keyboard: Key pressed Right Player X position + 300 * TimeDelta()
Keyboard: Key pressed Left Player X position - 300 * TimeDelta()

TimeDelta() is the last frame's duration in seconds. Multiplying by it keeps the speed the same on any computer: the player moves 300 pixels per second.

Tip: with the Platform or 8 Direction behavior you do not need to write this: the arrows already work. See Behaviors.

Example: one shot per press

Conditions Actions
Keyboard: Key just pressed Space Create an object Shot at the Player's position

With Key pressed the game would create a shot every frame while the space bar is held.

Changing screens with a key

For keys that change layout (menu, restart), use Key released. A key still held when the new layout starts would also fire the next layout's "just pressed" events.

Conditions Actions
Keyboard: Key released Return Change layout to Game