Rene, Greg and Gumm,
Thank you very much for your answers to my question.
Rene: Thank you for the comment of having "all objects able to accept events".
That is a powerful idea that I was just starting to realize, but you made it
very clear. In fact, I had started down the path by having s
I like clocks, timers and callbacks, Irv. I would not like to make a
game without them. :)
Here's a game clock. It's a little dated, but solid.
https://bitbucket.org/gummbum/gummworld2/src/e7dc9eaf45f3f6809d097968c0cb32edf6ea3bb9/gamelib/gummworld2/gameclock.py
Here's a newer game clock. It's n
Irv Kalb wrote:
So, my specific question is this: Is there any way for an object to create a
timer, that results to a callback within the same object?
There's nothing built into pygame for doing that as far as
I know. You'll have to build something yourself.
--
Greg
Hey ya,
so... a few ways.
# First threading. It's not so quick with threads, and delay can be longer
than you hope.
# https://docs.python.org/3/library/threading.html#threading.Timer
from threading import Timer
def hello():
print("hello, world")
seconds = 1.0
Timer(seconds, hello).start()
#
I've been working on porting a game that I wrote in a different
language/environment, and I want to make the Python/PyGame code as efficiently
as possible.
I have code in an object, that triggers an event that should occur, say 1
second later. I used pygame.set_timer, created an ID and set 1