Skip to main content

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

Start by downloading the package!

$ pip install pygame
$ pip install better_timers-gudninatan

Import timer manager

from better_timers import timers

OR

Create a new timer manager

from better_timers 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!")
    ...

All timers will be stopped upon calling pygame.quit(). You can also stop all the timers with this neat shortcut:

timers.end_all_timers()

Compatability

better_timers is compatible with both python 2 & 3.

Dependencies

better_timers 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.

Source Distribution

better_timers-gudninatan-0.0.3.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file better_timers-gudninatan-0.0.3.tar.gz.

File metadata

  • Download URL: better_timers-gudninatan-0.0.3.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.0

File hashes

Hashes for better_timers-gudninatan-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ff151ed236af125bfd5daea07b266e41f8a5860d67c578e1e3a0f952e8bfe43f
MD5 2e9896406f0c86cbe786a63c2324efd8
BLAKE2b-256 ec20581c03148d620aeeb089ec1f18143b06b356e2958c3755fc5386d15aeef0

See more details on using hashes here.

File details

Details for the file better_timers_gudninatan-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: better_timers_gudninatan-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.0

File hashes

Hashes for better_timers_gudninatan-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e061d57799fe4dfe43c3061024659b26fea0f4f41d35474fc7bfa330871be92e
MD5 70e77fa65d872317cc9fe09a0fc4be28
BLAKE2b-256 13de784201d961192ac1bf149448526439fae59ca77475d10f42de752b7b6ef8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page