List of Events

These are functions you can define and then bind using the when function.

starting

The starting event occurs when the game first loads. It cannot take any parameters, and it must produce the game state of the world. Typically, this will be a dictionary.

starting_handler()
Returns

The new state of the world.

The starting event.

updating

The updating event is by far the most common. It happens every step of the world.

updating_handler(world)
updating_handler(world, delta)
Parameters
  • world – The current state of the world. Initially, the value that you returned from your starting_handler.

  • delta (float) – Optional parameter representing the number of seconds that has passed since the last frame. Typically only necessary in high-performance games.

Binds a function to the

def update_the_world(world):
    pass

when('updating', update_the_world)

‘clicking’

The clicking event is when the mouse is clicked down.

clicking_handler(world, x, y)
clicking_handler(world, x, y, button)
Parameters
  • world – The current state of the world. Initially, the value that you returned from your starting_handler.

  • x (int) – The current horizontal position of the mouse.

  • y (int) – The current vertical position of the mouse.

  • button (str) – The mouse button that was clicked. One of either ‘left’, ‘middle’, or ‘right’.

Binds a function to the mouse being clicked.

def handle_mouse_click(world, x, y, button):
    pass

when('clicking', handle_mouse_click)

‘typing’

The typing event happens when you press a key on the keyboard.

typing_handler(world, key)
typing_handler(world, key, character)
Parameters
  • world – The current state of the world. Initially, the value that you returned from your starting_handler.

  • key (str) – A user-friendly name for whatever key was pressed, such as ‘left’ (for the left arrow) or ‘space’. A semi-complete list can be found at keys.

  • character (str) – A string representation of the keyboard character, representing what the character looks like when typed. The space key would be represented as a ‘ ‘ here.

Binds a function to the ‘typing’ handler.

def handle_the_keyboard(world):
    pass

when('typing', handle_the_keyboard)

All Possible Events

This is a list of all the events that are possible:

  • ‘input.mouse.down’

  • ‘input.mouse.up’

  • ‘input.keyboard.down’

Custom event test