1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>pygame.time — pygame v2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/pygame.css" />
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<link rel="shortcut icon" href="../_static/pygame.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="pygame._sdl2.touch" href="touch.html" />
<link rel="prev" title="pygame.tests" href="tests.html" />
</head><body>
<div class="document">
<div class="header">
<table>
<tr>
<td class="logo">
<a href="https://www.pygame.org/">
<img src="../_static/pygame_tiny.png"/>
</a>
<h5>pygame documentation</h5>
</td>
<td class="pagelinks">
<div class="top">
<a href="https://www.pygame.org/">Pygame Home</a> ||
<a href="../index.html">Help Contents</a> ||
<a href="../genindex.html">Reference Index</a>
<form action="../search.html" method="get" style="display:inline;float:right;">
<input name="q" value="" type="text">
<input value="search" type="submit">
</form>
</div>
<hr style="color:black;border-bottom:none;border-style: dotted;border-bottom-style:none;">
<p class="bottom"><b>Most useful stuff</b>:
<a href="color.html">Color</a> |
<a href="display.html">display</a> |
<a href="draw.html">draw</a> |
<a href="event.html">event</a> |
<a href="font.html">font</a> |
<a href="image.html">image</a> |
<a href="key.html">key</a> |
<a href="locals.html">locals</a> |
<a href="mixer.html">mixer</a> |
<a href="mouse.html">mouse</a> |
<a href="rect.html">Rect</a> |
<a href="surface.html">Surface</a> |
<a href="time.html">time</a> |
<a href="music.html">music</a> |
<a href="pygame.html">pygame</a>
</p>
<p class="bottom"><b>Advanced stuff</b>:
<a href="cursors.html">cursors</a> |
<a href="joystick.html">joystick</a> |
<a href="mask.html">mask</a> |
<a href="sprite.html">sprite</a> |
<a href="transform.html">transform</a> |
<a href="bufferproxy.html">BufferProxy</a> |
<a href="freetype.html">freetype</a> |
<a href="gfxdraw.html">gfxdraw</a> |
<a href="midi.html">midi</a> |
<a href="pixelarray.html">PixelArray</a> |
<a href="pixelcopy.html">pixelcopy</a> |
<a href="sndarray.html">sndarray</a> |
<a href="surfarray.html">surfarray</a> |
<a href="math.html">math</a>
</p>
<p class="bottom"><b>Other</b>:
<a href="camera.html">camera</a> |
<a href="sdl2_controller.html#module-pygame._sdl2.controller">controller</a> |
<a href="examples.html">examples</a> |
<a href="fastevent.html">fastevent</a> |
<a href="scrap.html">scrap</a> |
<a href="tests.html">tests</a> |
<a href="touch.html">touch</a> |
<a href="pygame.html#module-pygame.version">version</a>
</p>
</td>
</tr>
</table>
</div>
<div class="documentwrapper">
<div class="body" role="main">
<section id="module-pygame.time">
<span id="pygame-time"></span><dl class="definition">
<dt class="title module sig sig-object">
<code class="docutils literal notranslate"><span class="pre">pygame.time</span></code></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">pygame module for monitoring time</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 29%" />
<col style="width: 1%" />
<col style="width: 70%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="time.html#pygame.time.get_ticks">pygame.time.get_ticks</a></div>
</td>
<td>—</td>
<td>get the time in milliseconds</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="time.html#pygame.time.wait">pygame.time.wait</a></div>
</td>
<td>—</td>
<td>pause the program for an amount of time</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="time.html#pygame.time.delay">pygame.time.delay</a></div>
</td>
<td>—</td>
<td>pause the program for an amount of time</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="time.html#pygame.time.set_timer">pygame.time.set_timer</a></div>
</td>
<td>—</td>
<td>repeatedly create an event on the event queue</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="time.html#pygame.time.Clock">pygame.time.Clock</a></div>
</td>
<td>—</td>
<td>create an object to help track time</td>
</tr>
</tbody>
</table>
<p>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 <code class="docutils literal notranslate"><span class="pre">TIMER_RESOLUTION</span></code> constant.</p>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.time.get_ticks">
<span class="sig-prename descclassname"><span class="pre">pygame.time.</span></span><span class="sig-name descname"><span class="pre">get_ticks</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.time.get_ticks" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">get the time in milliseconds</span></div>
<div class="line"><span class="signature">get_ticks() -> milliseconds</span></div>
</div>
<p>Return the number of milliseconds since <code class="docutils literal notranslate"><span class="pre">pygame.init()</span></code> was called. Before
pygame is initialized this will always be 0.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.time.wait">
<span class="sig-prename descclassname"><span class="pre">pygame.time.</span></span><span class="sig-name descname"><span class="pre">wait</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.time.wait" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">pause the program for an amount of time</span></div>
<div class="line"><span class="signature">wait(milliseconds) -> time</span></div>
</div>
<p>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 <code class="docutils literal notranslate"><span class="pre">pygame.time.delay()</span></code> function.</p>
<p>This returns the actual number of milliseconds used.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.time.delay">
<span class="sig-prename descclassname"><span class="pre">pygame.time.</span></span><span class="sig-name descname"><span class="pre">delay</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.time.delay" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">pause the program for an amount of time</span></div>
<div class="line"><span class="signature">delay(milliseconds) -> time</span></div>
</div>
<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 <code class="docutils literal notranslate"><span class="pre">pygame.time.wait()</span></code>.</p>
<p>This returns the actual number of milliseconds used.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.time.set_timer">
<span class="sig-prename descclassname"><span class="pre">pygame.time.</span></span><span class="sig-name descname"><span class="pre">set_timer</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.time.set_timer" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">repeatedly create an event on the event queue</span></div>
<div class="line"><span class="signature">set_timer(event, millis) -> None</span></div>
<div class="line"><span class="signature">set_timer(event, millis, loops=0) -> None</span></div>
</div>
<p>Set an event 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>The <code class="docutils literal notranslate"><span class="pre">event</span></code> attribute can be a <code class="docutils literal notranslate"><span class="pre">pygame.event.Event</span></code> object or an integer
type that denotes an event.</p>
<p><code class="docutils literal notranslate"><span class="pre">loops</span></code> is an integer that denotes the number of events posted. If 0 (default)
then the events will keep getting posted, unless explicitly stopped.</p>
<p>To disable the timer for such an event, call the function again with the same
event argument with <code class="docutils literal notranslate"><span class="pre">millis</span></code> argument set to 0.</p>
<p>It is also worth mentioning that a particular event type can only be put on a
timer once. In other words, there cannot be two timers for the same event type.
Setting an event timer for a particular event discards the old one for that
event type.</p>
<p><code class="docutils literal notranslate"><span class="pre">loops</span></code> replaces the <code class="docutils literal notranslate"><span class="pre">once</span></code> argument, and this does not break backward
compatability</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0.0.dev3: </span>once argument added.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in pygame 2.0.1: </span>event argument supports <code class="docutils literal notranslate"><span class="pre">pygame.event.Event</span></code> object</p>
</div>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.0.1: </span>added loops argument to replace once argument</p>
</div>
</dd></dl>
<dl class="py class definition">
<dt class="sig sig-object py title" id="pygame.time.Clock">
<span class="sig-prename descclassname"><span class="pre">pygame.time.</span></span><span class="sig-name descname"><span class="pre">Clock</span></span><a class="headerlink" href="#pygame.time.Clock" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">create an object to help track time</span></div>
<div class="line"><span class="signature">Clock() -> Clock</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 41%" />
<col style="width: 1%" />
<col style="width: 57%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="time.html#pygame.time.Clock.tick">pygame.time.Clock.tick</a></div>
</td>
<td>—</td>
<td>update the clock</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="time.html#pygame.time.Clock.tick_busy_loop">pygame.time.Clock.tick_busy_loop</a></div>
</td>
<td>—</td>
<td>update the clock</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="time.html#pygame.time.Clock.get_time">pygame.time.Clock.get_time</a></div>
</td>
<td>—</td>
<td>time used in the previous tick</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="time.html#pygame.time.Clock.get_rawtime">pygame.time.Clock.get_rawtime</a></div>
</td>
<td>—</td>
<td>actual time used in the previous tick</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="time.html#pygame.time.Clock.get_fps">pygame.time.Clock.get_fps</a></div>
</td>
<td>—</td>
<td>compute the clock framerate</td>
</tr>
</tbody>
</table>
<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>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.time.Clock.tick">
<span class="sig-name descname"><span class="pre">tick</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.time.Clock.tick" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">update the clock</span></div>
<div class="line"><span class="signature">tick(framerate=0) -> milliseconds</span></div>
</div>
<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
<code class="docutils literal notranslate"><span class="pre">Clock.tick(40)</span></code> 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>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.time.Clock.tick_busy_loop">
<span class="sig-name descname"><span class="pre">tick_busy_loop</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.time.Clock.tick_busy_loop" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">update the clock</span></div>
<div class="line"><span class="signature">tick_busy_loop(framerate=0) -> milliseconds</span></div>
</div>
<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
<code class="docutils literal notranslate"><span class="pre">Clock.tick_busy_loop(40)</span></code> once per frame, the program will never run at
more than 40 frames per second.</p>
<p>Note that this function uses <a class="tooltip reference internal" href="#pygame.time.delay" title=""><code class="xref py py-func docutils literal notranslate"><span class="pre">pygame.time.delay()</span></code><span class="tooltip-content">pause the program for an amount of time</span></a>, which uses lots
of CPU in a busy loop to make sure that timing is more accurate.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 1.8.</span></p>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.time.Clock.get_time">
<span class="sig-name descname"><span class="pre">get_time</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.time.Clock.get_time" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">time used in the previous tick</span></div>
<div class="line"><span class="signature">get_time() -> milliseconds</span></div>
</div>
<p>The number of milliseconds that passed between the previous two calls to
<code class="docutils literal notranslate"><span class="pre">Clock.tick()</span></code>.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.time.Clock.get_rawtime">
<span class="sig-name descname"><span class="pre">get_rawtime</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.time.Clock.get_rawtime" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">actual time used in the previous tick</span></div>
<div class="line"><span class="signature">get_rawtime() -> milliseconds</span></div>
</div>
<p>Similar to <code class="docutils literal notranslate"><span class="pre">Clock.get_time()</span></code>, but does not include any time used
while <code class="docutils literal notranslate"><span class="pre">Clock.tick()</span></code> was delaying to limit the framerate.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.time.Clock.get_fps">
<span class="sig-name descname"><span class="pre">get_fps</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.time.Clock.get_fps" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">compute the clock framerate</span></div>
<div class="line"><span class="signature">get_fps() -> float</span></div>
</div>
<p>Compute your game's framerate (in frames per second). It is computed by
averaging the last ten calls to <code class="docutils literal notranslate"><span class="pre">Clock.tick()</span></code>.</p>
</dd></dl>
</dd></dl>
</dd></dl>
</section>
<br /><br />
<hr />
<a href="https://github.com/pygame/pygame/edit/main/docs/reST/ref/time.rst" rel="nofollow">Edit on GitHub</a>
<div class="clearer"></div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="touch.html" title="pygame._sdl2.touch"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="tests.html" title="pygame.tests"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">pygame v2.1.2 documentation</a> »</li>
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame.time</span></code></a></li>
<script type="text/javascript" src="https://www.pygame.org/comment/jquery.plugin.docscomments.js"></script>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2000-2021, pygame developers.
</div>
</body>
</html>
|