File: time.rst

package info (click to toggle)
pygame 1.9.6%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 12,060 kB
  • sloc: ansic: 59,765; python: 31,220; objc: 334; makefile: 57; cpp: 25
file content (151 lines) | stat: -rw-r--r-- 4,881 bytes parent folder | download
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
.. include:: common.txt

:mod:`pygame.time`
==================

.. module:: pygame.time
   :synopsis: pygame module for monitoring time

| :sl:`pygame module for monitoring 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.

.. function:: get_ticks

   | :sl:`get the time in milliseconds`
   | :sg:`get_ticks() -> milliseconds`

   Return the number of milliseconds since ``pygame.init()`` was called. Before
   pygame is initialized this will always be 0.

   .. ## pygame.time.get_ticks ##

.. function:: wait

   | :sl:`pause the program for an amount of time`
   | :sg:`wait(milliseconds) -> 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()`` function.

   This returns the actual number of milliseconds used.

   .. ## pygame.time.wait ##

.. function:: delay

   | :sl:`pause the program for an amount of time`
   | :sg:`delay(milliseconds) -> 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()``.

   This returns the actual number of milliseconds used.

   .. ## pygame.time.delay ##

.. function:: set_timer

   | :sl:`repeatedly create an event on the event queue`
   | :sg:`set_timer(eventid, milliseconds) -> 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.set_timer ##

.. class:: Clock

   | :sl:`create an object to help track time`
   | :sg:`Clock() -> Clock`

   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.

   .. method:: tick

      | :sl:`update the clock`
      | :sg:`tick(framerate=0) -> milliseconds`
      | :sg:` -> `

      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 ##

   .. method:: tick_busy_loop

      | :sl:`update the clock`
      | :sg:`tick_busy_loop(framerate=0) -> milliseconds`
      | :sg:` -> `

      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_busy_loop(40)`` once per frame, the program will never run at 
      more than 40 frames per second.

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

      .. versionadded:: 1.8

      .. ## Clock.tick_busy_loop ##

   .. method:: get_time

      | :sl:`time used in the previous tick`
      | :sg:`get_time() -> milliseconds`

      The number of milliseconds that passed between the previous two calls to
      ``Clock.tick()``.

      .. ## Clock.get_time ##

   .. method:: get_rawtime

      | :sl:`actual time used in the previous tick`
      | :sg:`get_rawtime() -> milliseconds`

      Similar to ``Clock.get_time()``, but does not include any time used
      while ``Clock.tick()`` was delaying to limit the framerate.

      .. ## Clock.get_rawtime ##

   .. method:: get_fps

      | :sl:`compute the clock framerate`
      | :sg:`get_fps() -> float`

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

      .. ## Clock.get_fps ##

   .. ## pygame.time.Clock ##

.. ## pygame.time ##