pygame / docs / ref / time.html

<html>
<title>time - Pygame Documentation</title>
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>


<table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%'>
<tr>
<td bgcolor='#c2fc20' style='padding: 6px;' align=center valign=center><a href='http://www.pygame.org/'><img src='../pygame_tiny.gif' border=0 width=200 height=60></a><br><b>pygame documentation</b></td>
<td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center>
	||&nbsp;
	<a href=http://www.pygame.org>Pygame Home</a> &nbsp;||&nbsp;
	<a href=../index.html>Help Contents</a> &nbsp;||
	<a href=index.html>Reference Index</a> &nbsp;||
	<br>&nbsp;<br>
	
<a href=cdrom.html>Cdrom</a>&nbsp;||&nbsp;
<a href=cursors.html>Cursors</a>&nbsp;||&nbsp;
<a href=display.html>Display</a>&nbsp;||&nbsp;
<a href=draw.html>Draw</a>&nbsp;||&nbsp;
<a href=event.html>Event</a>&nbsp;||&nbsp;
<a href=font.html>Font</a>&nbsp;||&nbsp;
<a href=image.html>Image</a>&nbsp;||&nbsp;
<a href=joystick.html>Joystick</a>&nbsp;||&nbsp;
<a href=key.html>Key</a>&nbsp;||&nbsp;
<a href=mask.html>Mask</a>&nbsp;||&nbsp;
<a href=mixer.html>Mixer</a>&nbsp;||&nbsp;
<a href=mouse.html>Mouse</a>&nbsp;||&nbsp;
<a href=movie.html>Movie</a>&nbsp;||&nbsp;
<a href=music.html>Music</a>&nbsp;||&nbsp;
<a href=overlay.html>Overlay</a>&nbsp;||&nbsp;
<a href=pixelarray.html>Pixelarray</a>&nbsp;||&nbsp;
<a href=pygame.html>Pygame</a>&nbsp;||&nbsp;
<a href=rect.html>Rect</a>&nbsp;||&nbsp;
<a href=scrap.html>Scrap</a>&nbsp;||&nbsp;
<a href=sndarray.html>Sndarray</a>&nbsp;||&nbsp;
<a href=sprite.html>Sprite</a>&nbsp;||&nbsp;
<a href=surface.html>Surface</a>&nbsp;||&nbsp;
<a href=surfarray.html>Surfarray</a>&nbsp;||&nbsp;
<a href=time.html>Time</a>&nbsp;||&nbsp;
<a href=transform.html>Transform</a>
</td></tr></table>
<br>


<a name="pygame.time">
<big><b>pygame.time</big></b><br><ul>
  <i>pygame module for monitoring time</i><br>
<ul><small><table>
  <tr><td><a href="time.html#pygame.time.get_ticks">pygame.time.get_ticks</a> - <font size=-1>get the time in milliseconds</font></td><td>get the time in milliseconds</td></tr>
  <tr><td><a href="time.html#pygame.time.wait">pygame.time.wait</a> - <font size=-1>pause the program for an amount of time</font></td><td>pause the program for an amount of time</td></tr>
  <tr><td><a href="time.html#pygame.time.delay">pygame.time.delay</a> - <font size=-1>pause the program for an amount of time</font></td><td>pause the program for an amount of time</td></tr>
  <tr><td><a href="time.html#pygame.time.set_timer">pygame.time.set_timer</a> - <font size=-1>repeatedly create an event on the event queue</font></td><td>repeatedly create an event on the event queue</td></tr>
  <tr><td><a href="time.html#pygame.time.Clock">pygame.time.Clock</a> - <font size=-1>create an object to help track time</font></td><td>create an object to help track time</td></tr>
</table></small></ul>
<p>Times in pygame are represented in milliseconds (1/1000 seconds). Most platforms have a limited time resolution of around 10 milliseconds. </p>
<!--COMMENTS:pygame.time--> &nbsp;<br> 


<a name="pygame.time.get_ticks">
<big><b>pygame.time.get_ticks</big></b><br><ul>
  <i>get the time in milliseconds</i><br>
  <tt>pygame.time.get_ticks(): return milliseconds</tt><br>
<p>Return the number of millisconds since <tt><a href="pygame.html#pygame.init">pygame.init</a> - <font size=-1>initialize all imported pygame modules</font></tt> was called. Before pygame is initialized this will always be 0. </p>
<!--COMMENTS:pygame.time.get_ticks--> &nbsp;<br> 
<br></ul>


<a name="pygame.time.wait">
<big><b>pygame.time.wait</big></b><br><ul>
  <i>pause the program for an amount of time</i><br>
  <tt>pygame.time.wait(milliseconds): return time</tt><br>
<p>Will pause for a given number of milliseconds. This function sleeps the process to share the processor with other programs. <tt>A</tt> program that waits for even a few milliseconds will consume very little processor time. It is slightly less accurate than the <tt><a href="time.html#pygame.time.delay">pygame.time.delay</a> - <font size=-1>pause the program for an amount of time</font></tt> function. </p>
<p>This returns the actual number of milliseconds used. </p>
<!--COMMENTS:pygame.time.wait--> &nbsp;<br> 
<br></ul>


<a name="pygame.time.delay">
<big><b>pygame.time.delay</big></b><br><ul>
  <i>pause the program for an amount of time</i><br>
  <tt>pygame.time.delay(milliseconds): return time</tt><br>
<p>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 <tt><a href="time.html#pygame.time.wait">pygame.time.wait</a> - <font size=-1>pause the program for an amount of time</font></tt>. </p>
<p>This returns the actual number of milliseconds used. </p>
<!--COMMENTS:pygame.time.delay--> &nbsp;<br> 
<br></ul>


<a name="pygame.time.set_timer">
<big><b>pygame.time.set_timer</big></b><br><ul>
  <i>repeatedly create an event on the event queue</i><br>
  <tt>pygame.time.set_timer(eventid, milliseconds): return None</tt><br>
<p>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. </p>
<p>Every event type can have a separate timer attached to it. It is best to use the value between <tt>pygame.USEREVENT</tt> and <tt>pygame.NUMEVENTS</tt>. </p>
<p>To disable the timer for an event, set the milliseconds argument to 0. </p>
<!--COMMENTS:pygame.time.set_timer--> &nbsp;<br> 
<br></ul>


<a name="pygame.time.Clock">
<big><b>pygame.time.Clock</big></b><br><ul>
  <i>create an object to help track time</i><br>
  <tt>pygame.time.Clock(): return Clock</tt><br>
<ul><small><table>
  <tr><td><a href="time.html#Clock.tick">Clock.tick</a> - <font size=-1>update the clock</font></td><td>update the clock</td></tr>
  <tr><td><a href="time.html#Clock.tick_busy_loop">Clock.tick_busy_loop</a> - <font size=-1>update the clock</font></td><td>update the clock</td></tr>
  <tr><td><a href="time.html#Clock.get_time">Clock.get_time</a> - <font size=-1>time used in the previous tick</font></td><td>time used in the previous tick</td></tr>
  <tr><td><a href="time.html#Clock.get_rawtime">Clock.get_rawtime</a> - <font size=-1>actual time used in the previous tick</font></td><td>actual time used in the previous tick</td></tr>
  <tr><td><a href="time.html#Clock.get_fps">Clock.get_fps</a> - <font size=-1>compute the clock framerate</font></td><td>compute the clock framerate</td></tr>
</table></small></ul>
<p>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. </p>
<!--COMMENTS:pygame.time.Clock--> &nbsp;<br> 


<a name="Clock.tick">
<big><b>Clock.tick</big></b><br><ul>
  <i>update the clock</i><br>
  <tt>Clock.tick(framerate=0): return milliseconds</tt><br>
  <tt>control timer events</tt><br>
<p>This method should be called once per frame. It will compute how many milliseconds have passed since the previous call. </p>
<p>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 <tt>Clock.tick(40)</tt> once per frame, the program will never run at more than 40 frames per second. </p>
<p>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. </p>
<!--COMMENTS:Clock.tick--> &nbsp;<br> 
<br></ul>


<a name="Clock.tick_busy_loop">
<big><b>Clock.tick_busy_loop</big></b><br><ul>
  <i>update the clock</i><br>
  <tt>Clock.tick_busy_loop(framerate=0): return milliseconds</tt><br>
  <tt>control timer events</tt><br>
<p>This method should be called once per frame. It will compute how many milliseconds have passed since the previous call. </p>
<p>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 <tt>Clock.tick(40)</tt> once per frame, the program will never run at more than 40 frames per second. </p>
<p>Note that this function uses <tt>pygame.time.delay</tt>, which uses lots of cpu in a busy loop to make sure that timing is more acurate. </p>
<!--COMMENTS:Clock.tick_busy_loop--> &nbsp;<br> 
<br></ul>


<a name="Clock.get_time">
<big><b>Clock.get_time</big></b><br><ul>
  <i>time used in the previous tick</i><br>
  <tt>Clock.get_time(): return milliseconds</tt><br>
<p>Returns the parameter passed to the last call to <tt><a href="time.html#Clock.tick">Clock.tick</a> - <font size=-1>update the clock</font></tt>. It is the number of milliseconds passed between the previous two calls to <tt>Pygame.tick()</tt>. </p>
<!--COMMENTS:Clock.get_time--> &nbsp;<br> 
<br></ul>


<a name="Clock.get_rawtime">
<big><b>Clock.get_rawtime</big></b><br><ul>
  <i>actual time used in the previous tick</i><br>
  <tt>Clock.get_rawtime(): return milliseconds</tt><br>
<p>Similar to <tt><a href="time.html#Clock.get_time">Clock.get_time</a> - <font size=-1>time used in the previous tick</font></tt>, but this does not include any time used while <tt><a href="time.html#Clock.tick">Clock.tick</a> - <font size=-1>update the clock</font></tt> was delaying to limit the framerate. </p>
<!--COMMENTS:Clock.get_rawtime--> &nbsp;<br> 
<br></ul>


<a name="Clock.get_fps">
<big><b>Clock.get_fps</big></b><br><ul>
  <i>compute the clock framerate</i><br>
  <tt>Clock.get_fps(): return float</tt><br>
<p>Compute your game's framerate (in frames per second). It is computed by averaging the last few calls to <tt><a href="time.html#Clock.tick">Clock.tick</a> - <font size=-1>update the clock</font></tt>. </p>
<!--COMMENTS:Clock.get_fps--> &nbsp;<br> 
<br></ul>
<br></ul>
<br></ul>

</body></html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.