timestep.Timestep
Class that handles the framerate-independent game loop.
Timestep(step) -> Timestep
-
timestep.Timestep.update
Run game logic
-
timestep.Timestep.render
Blit and draw all objects
-
timestep.Timestep.run_game
Run the game loop
Class that runs the game loop and does all the calculations to make the game framerate independent. step is the time (in seconds) between rendering update, for example 1/60.
class game_loop(timestep.Timestep):
...
game = game_loop(1/60)
update()
Run game logic
update(*args, **kwargs) -> None
This method is intended to be overwriten with Character updates and the pygame event loop. Should not be called manually.
...
def update(self):
# standard pygame event loop
for event in pygame.event.get():
if event.type == QUIT:
game_running = False
# update Characters
player.update()
render()
Blit and draw all objects
render(alpha) -> None
This method is intended to be overwriten with any code that draws to the screen. alpha should be passed in to all Character.draw()
. Should not be called manually.
...
def render(self, alpha):
screen.fill((0, 0, 0))
player.draw(screen, alpha)
pygame.display.flip()
run_game()
Run the game loop
run_game() -> None
Run within a while loop. Calls Timestep.update()
and Timestep.render()
periodically to make the game framerate independent.
game_running = True
while game_running:
game.run_game()
pygame.quit()