pygame documentation | || Pygame Home || Help Contents || Reference Index || Camera || Cdrom || Color || Cursors || Display || Draw || Event || Examples || Font || Gfxdraw || Image || Joystick || Key || Locals || Mask || Midi || Mixer || Mouse || Movie || Music || Overlay || Pixelarray || Pygame || Rect || Scrap || Sndarray || Sprite || Surface || Surfarray || Tests || Time || Transform

pygame.time

pygame module for monitoring time

pygame.time.get_ticks - get the time in milliseconds | get the time in milliseconds
pygame.time.wait - pause the program for an amount of time | pause the program for an amount of time
pygame.time.delay - pause the program for an amount of time | pause the program for an amount of time
pygame.time.set_timer - repeatedly create an event on the event queue | repeatedly create an event on the event queue
pygame.time.Clock - create an object to help track time | create an object to help track time

Times in pygame are represented in milliseconds (1/1000 seconds). Most platforms have a limited time resolution of around 10 milliseconds. This resolution, in milliseconds, is given in the `TIMER_RESOLUTION` constant.

pygame.time.get_ticks

get the time in milliseconds
`pygame.time.get_ticks(): return milliseconds`

Return the number of millisconds since `pygame.init - initialize all imported pygame modules` was called. Before pygame is initialized this will always be 0.

pygame.time.wait

pause the program for an amount of time
`pygame.time.wait(milliseconds): return time`

Will pause for a given number of milliseconds. This function sleeps the process to share the processor with other programs. `A` program that waits for even a few milliseconds will consume very little processor time. It is slightly less accurate than the `pygame.time.delay - pause the program for an amount of time` function.

This returns the actual number of milliseconds used.

pygame.time.delay

pause the program for an amount of time
`pygame.time.delay(milliseconds): return time`

Will pause for a given number of milliseconds. This function will use the processor (rather than sleeping) in order to make the delay more accurate than `pygame.time.wait - pause the program for an amount of time`.

This returns the actual number of milliseconds used.

pygame.time.set_timer

repeatedly create an event on the event queue
`pygame.time.set_timer(eventid, milliseconds): return None`

Set an event type to appear on the event queue every given number of milliseconds. The first event will not appear until the amount of time has passed.

Every event type can have a separate timer attached to it. It is best to use the value between `pygame.USEREVENT` and `pygame.NUMEVENTS`.

To disable the timer for an event, set the milliseconds argument to 0.

pygame.time.Clock

create an object to help track time
`pygame.time.Clock(): return Clock`

Clock.tick - update the clock | update the clock
Clock.tick_busy_loop - update the clock | update the clock
Clock.get_time - time used in the previous tick | time used in the previous tick
Clock.get_rawtime - actual time used in the previous tick | actual time used in the previous tick
Clock.get_fps - compute the clock framerate | compute the clock framerate

Creates a new Clock object that can be used to track an amount of time. The clock also provides several functions to help control a game's framerate.

Clock.tick

update the clock
`Clock.tick(framerate=0): return milliseconds`
`control timer events`

This method should be called once per frame. It will compute how many milliseconds have passed since the previous call.

If you pass the optional framerate argument the function will delay to keep the game running slower than the given ticks per second. This can be used to help limit the runtime speed of a game. By calling `Clock.tick(40)` once per frame, the program will never run at more than 40 frames per second.

Note that this function uses SDL_Delay function which is not accurate on every platform, but does not use much cpu. Use tick_busy_loop if you want an accurate timer, and don't mind chewing cpu.

Clock.tick_busy_loop

update the clock
`Clock.tick_busy_loop(framerate=0): return milliseconds`
`control timer events`

This method should be called once per frame. It will compute how many milliseconds have passed since the previous call.

If you pass the optional framerate argument the function will delay to keep the game running slower than the given ticks per second. This can be used to help limit the runtime speed of a game. By calling `Clock.tick(40)` once per frame, the program will never run at more than 40 frames per second.

Note that this function uses `pygame.time.delay`, which uses lots of cpu in a busy loop to make sure that timing is more acurate.

New in pygame `1.8.0`.

Clock.get_time

time used in the previous tick
`Clock.get_time(): return milliseconds`

Returns the parameter passed to the last call to `Clock.tick - update the clock`. It is the number of milliseconds passed between the previous two calls to `Pygame.tick()`.

Clock.get_rawtime

actual time used in the previous tick
`Clock.get_rawtime(): return milliseconds`

Similar to `Clock.get_time - time used in the previous tick`, but this does not include any time used while `Clock.tick - update the clock` was delaying to limit the framerate.

Clock.get_fps

compute the clock framerate
`Clock.get_fps(): return float`

Compute your game's framerate (in frames per second). It is computed by averaging the last few calls to `Clock.tick - update the clock`.