Spawning Multiple Objects In Pygame (Using Timers)

Vishal Rashmika published on
1 min, 90 words

Categories: Pygame

Timers

  • custom user events that are triggered in certain time intervals

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