Skip to main content

Better timers for pygame

Project description


Better timers for pygame with demo

For in-depth explanation (in Icelandic) see:

Quick start

Import timer manager

from BetterTimers import timers


Create a new timer manager

from BetterTimers import BetterTimers
timers = BetterTimers()

Add new timers that will automatically go to the event queue repeatedly, every N milliseconds using this format.
timers.set_timer(event, ms, *delay_ms)
You can pass in both the regular USEREVENT types or create your own pygame.event.Event with any custom args and kwargs for unlimited possibilities. Override already established timers easily, or delete them entirely by passing in a rate of 0 or less.

genericEvent = USEREVENT + 1
randomEvent = USEREVENT + 2

coolEvent = pygame.event.Event(genericEvent, code="cool")
uncoolEvent = pygame.event.Event(genericEvent, code="uncool")

timers.set_timer(coolEvent, 500) # Sets a timer for 500 milliseconds
timers.set_timer(coolEvent, 2000, 300) # Overrides old 500 rate timer, with delay

timers.set_timer(uncoolEvent, 1000) # New genericEvent timer with a different code

timers.set_timer(randomEvent, 5000) # Traditional timer set with USEREVENT
timers.set_timer(randomEvent, 0) # Timer stopped

You will recieve these events in the pygame event queue just as you would expect.

while True:
    for event in pygame.event.get():
        if event == coolEvent:
            print("How cool!")

You can also stop all the timers with this neat shortcut. Please be sure to stop all timers before exiting the program:


Compatability is compatible with both python 2 & 3.

Dependencies is dependant on pygame.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for better-timers-gudninatan, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size better_timers_gudninatan-0.0.2-py3-none-any.whl (4.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size better_timers-gudninatan-0.0.2.tar.gz (3.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page