Skip to main content
Version: Release

Events

Events flow from the Manager into the active scene, then down through layers to entities and GUI widgets. You can intercept them at several points.

Scene event order​

When a scene receives an event, propagation stops as soon as event.consumed is set:

  1. do_early_handle_event(self, event) — earliest scene hook
  2. early_actions — scene early ActionContainer
  3. Player input is skipped while a transition is running
  4. Each scene layer via layer.process_event(event) (entities on that layer, including scene.root on hud)
  5. handle_event(self, event) — main scene hook
  6. actions — scene ActionContainer
class MyScene(bf.Scene):
def do_early_handle_event(self, event):
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
event.consumed = True

def handle_event(self, event):
if event.type == pygame.KEYDOWN and event.key == pygame.K_p:
self.toggle_pause()

Entity event order​

For each entity:

  1. process_actions(event)
  2. handle_event(event)

Consuming events​

Set event.consumed = True (or use an Action with set_consume_event(True)) to stop further propagation.