Delta Time

Code

import arcade

GAME_TITLE = 'Drawing Example'
WINDOW_HEIGHT = 600
WINDOW_WIDTH = 600


def on_draw(delta_time):
    arcade.start_render()
    message = GAME_TITLE + ': ' + str(delta_time)
    arcade.draw_text(message, 200, 300, arcade.color.BLACK, 12)


def main():
    arcade.open_window(WINDOW_HEIGHT, WINDOW_WIDTH, GAME_TITLE)
    arcade.set_background_color(arcade.color.WHEAT)
    arcade.schedule(on_draw, 1 / 2)
    arcade.run()


if __name__ == '__main__':
    main()

Analysis

  • The previous example left ‘delta_time’ unexplained
  • ‘arcade.schedule’ runs our ‘on_draw’ function every 1/2 second
  • But it might not be exactly half a second…if your computer is bogged down, or the game gets laggy, it might get behind
  • So arcade.schedule keeps track of how long it has been since the last time your function was called
  • It passes this value to your function as the first argument
  • We change our text to include the value of this argument, so we get a better sense