Better timers for pygame
Project description
BetterTimers
Better timers for pygame with demo
For in-depth explanation (in Icelandic) see: https://gudninathan.blogspot.is/2017/05/pygame-og-events-1-genericevent.html
Quick start
Import timer manager
from BetterTimers import timers
OR
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:
timers.end_all_timers()
Compatability
BetterTimers.py is compatible with both python 2 & 3.
Dependencies
BetterTimers.py is dependant on pygame.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for better_timers-gudninatan-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a7ec416f764400248db631e8e26740f519b3b1224f8f4a9659bc848f2353ab3 |
|
MD5 | c773074f39178b4df2a3fa17ef792f24 |
|
BLAKE2b-256 | f58cbdb1a555ccfa6a2c20b498901e5cf4a00df84c32523262e518baa71570f5 |
Hashes for better_timers_gudninatan-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01d82498082c28f738e5e71717e3387f1b01a023bf0d12ce355b6d8d5b59e63c |
|
MD5 | 573e4c269226d1a442fc6d9775672c3f |
|
BLAKE2b-256 | 17d385f4bd607513ef9f291ef86b6820fb0d2b1bed103dc029ed426b92ae72b5 |