STEP 9: We need to make our event run more often!

We use an event handler to tell the program what signal to listen for and which event to run.

  • Find the interval event handler: stage.event_interval(interval,·2)¬
  • See the 2? That means the interval event runs once every 2 seconds.
  • Change the 2 to 1. Now the event runs once every second!

To navigate the page using the TAB key, first press ESC to exit the code editor.

stage.set_background("moon") sprite = codesters.Sprite("hedgehog", 0, -210) score = 0 #my_display = codesters.Display(my_var, x, y) score_display = codesters.Display(score, -210, -210) time = 60 #my_display = codesters.Display(my_var, x, y) time_display = codesters.Display(time, 210, -210) def left_key(): rotation = sprite.get_rotation() print(rotation) sprite.set_rotation(rotation+3) # add other actions... stage.event_key("left", left_key) def right_key(): rotation = sprite.get_rotation() print(rotation) sprite.set_rotation(rotation-3) # add other actions... stage.event_key("right", right_key) def interval(): global time time -=1 time_display.update(time) stage.event_interval(interval, 2)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)