../

Spawning Multiple Objects In Pygame (Using Timers)

Timers

Method

  1. Create Custom Events
  2. Tell pygame to trigger that event continously
  3. Add code in event loop to do something the timer is triggered

pygame.time.set_timer(evetn to be triggered, time time interval in milliseconds)

  1. we create a list of obstacles rectangles
  2. everytime the timer triggers we add a new rectangle to that list
  3. we move every rectangle in that list to the left on every frame
  4. delete rectangles that goes too far left

Tags: /python/ /python3/ /pygame/ /gamedev/ /tutorial/ /animation/