13 Timers
This chapter is about timers. A timer allows your program to count or wait for a given amount of time before moving on to perform some other action. In the world of text-based Python programs, this is easily achieved with time.sleep
()
by specifying a number of seconds to sleep. To pause for two and a half seconds, you could write:
import time
time.sleep(2.5)
However, in the world of pygame, and event-driven programming in general, the user should always be able to interact with the program, so pausing in this way is inappropriate. A call to time.sleep()
would make the program nonreactive during the sleeping period.
Instead, the ...
Get Object-Oriented Python now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.