~ubuntu-branches/ubuntu/maverick/pygame/maverick

« back to all changes in this revision

Viewing changes to docs/ref/sprite.html

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-01-14 17:02:11 UTC
  • mfrom: (1.3.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100114170211-21eop2ja7mr9vdcr
Tags: 1.9.1release-0ubuntu1
* New upstream version (lp: #433304)
* debian/control:
  - build-depends on libportmidi-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
<html>
3
 
<title>sprite - Pygame Documentation</title>
4
 
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>
5
 
 
6
 
 
7
 
<table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%'>
8
 
<tr>
9
 
<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>
10
 
<td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center>
11
 
        ||&nbsp;
12
 
        <a href=http://www.pygame.org>Pygame Home</a> &nbsp;||&nbsp;
13
 
        <a href=../index.html>Help Contents</a> &nbsp;||
14
 
        <a href=index.html>Reference Index</a> &nbsp;||
15
 
        <br>&nbsp;<br>
16
 
        
17
 
<a href="cdrom.html">Cdrom</a>&nbsp;||&nbsp;
18
 
<a href="color.html">Color</a>&nbsp;||&nbsp;
19
 
<a href="cursors.html">Cursors</a>&nbsp;||&nbsp;
20
 
<a href="display.html">Display</a>&nbsp;||&nbsp;
21
 
<a href="draw.html">Draw</a>&nbsp;||&nbsp;
22
 
<a href="event.html">Event</a>&nbsp;||&nbsp;
23
 
<a href="font.html">Font</a>&nbsp;||&nbsp;
24
 
<a href="image.html">Image</a>&nbsp;||&nbsp;
25
 
<a href="joystick.html">Joystick</a>&nbsp;||&nbsp;
26
 
<a href="key.html">Key</a>&nbsp;||&nbsp;
27
 
<a href="mask.html">Mask</a>&nbsp;||&nbsp;
28
 
<a href="mixer.html">Mixer</a>&nbsp;||&nbsp;
29
 
<a href="mouse.html">Mouse</a>&nbsp;||&nbsp;
30
 
<a href="movie.html">Movie</a>&nbsp;||&nbsp;
31
 
<a href="music.html">Music</a>&nbsp;||&nbsp;
32
 
<a href="overlay.html">Overlay</a>&nbsp;||&nbsp;
33
 
<a href="pixelarray.html">Pixelarray</a>&nbsp;||&nbsp;
34
 
<a href="pygame.html">Pygame</a>&nbsp;||&nbsp;
35
 
<a href="rect.html">Rect</a>&nbsp;||&nbsp;
36
 
<a href="scrap.html">Scrap</a>&nbsp;||&nbsp;
37
 
<a href="sndarray.html">Sndarray</a>&nbsp;||&nbsp;
38
 
<a href="sprite.html">Sprite</a>&nbsp;||&nbsp;
39
 
<a href="surface.html">Surface</a>&nbsp;||&nbsp;
40
 
<a href="surfarray.html">Surfarray</a>&nbsp;||&nbsp;
41
 
<a href="time.html">Time</a>&nbsp;||&nbsp;
42
 
<a href="transform.html">Transform</a>
43
 
</td></tr></table>
44
 
<br>
45
 
 
46
 
 
47
 
<a name="pygame.sprite">
48
 
<big><b>pygame.sprite</big></b><br><ul>
49
 
  <i>pygame module with basic game object classes</i><br>
50
 
<ul><small><table>
51
 
  <tr><td><a href="sprite.html#pygame.sprite.Sprite">pygame.sprite.Sprite</a> - <font size=-1>simple base class for visible game objects</font></td><td>simple base class for visible game objects</td></tr>
52
 
  <tr><td><a href="sprite.html#pygame.sprite.DirtySprite">pygame.sprite.DirtySprite</a> - <font size=-1>a more featureful subclass of Sprite with more attributes</font></td><td>a more featureful subclass of Sprite with more attributes</td></tr>
53
 
  <tr><td><a href="sprite.html#pygame.sprite.Group">pygame.sprite.Group</a> - <font size=-1>container class for many Sprites</font></td><td>container class for many Sprites</td></tr>
54
 
  <tr><td><a href="sprite.html#pygame.sprite.RenderUpdates">pygame.sprite.RenderUpdates</a> - <font size=-1>Group class that tracks dirty updates</font></td><td>Group class that tracks dirty updates</td></tr>
55
 
  <tr><td><a href="sprite.html#pygame.sprite.OrderedUpdates">pygame.sprite.OrderedUpdates</a> - <font size=-1>RenderUpdates class that draws Sprites in order of addition</font></td><td>RenderUpdates class that draws Sprites in order of addition</td></tr>
56
 
  <tr><td><a href="sprite.html#pygame.sprite.LayeredUpdates">pygame.sprite.LayeredUpdates</a> - <font size=-1>LayeredUpdates Group handles layers, that draws like OrderedUpdates.</font></td><td>LayeredUpdates Group handles layers, that draws like OrderedUpdates.</td></tr>
57
 
  <tr><td><a href="sprite.html#pygame.sprite.LayeredDirty">pygame.sprite.LayeredDirty</a> - <font size=-1>LayeredDirty Group is for DirtySprites.  Subclasses LayeredUpdates.</font></td><td>LayeredDirty Group is for DirtySprites.  Subclasses LayeredUpdates.</td></tr>
58
 
  <tr><td><a href="sprite.html#pygame.sprite.GroupSingle">pygame.sprite.GroupSingle</a> - <font size=-1>Group container that holds a single Sprite</font></td><td>Group container that holds a single Sprite</td></tr>
59
 
  <tr><td><a href="sprite.html#pygame.sprite.spritecollide">pygame.sprite.spritecollide</a> - <font size=-1>find Sprites in a Group that intersect another Sprite</font></td><td>find Sprites in a Group that intersect another Sprite</td></tr>
60
 
  <tr><td><a href="sprite.html#pygame.sprite.collide_rect">pygame.sprite.collide_rect</a> - <font size=-1>collision detection between two sprites, using rects.</font></td><td>collision detection between two sprites, using rects.</td></tr>
61
 
  <tr><td><a href="sprite.html#pygame.sprite.collide_rect_ratio">pygame.sprite.collide_rect_ratio</a> - <font size=-1>collision detection between two sprites, using rects scaled to a ratio.</font></td><td>collision detection between two sprites, using rects scaled to a ratio.</td></tr>
62
 
  <tr><td><a href="sprite.html#pygame.sprite.collide_circle">pygame.sprite.collide_circle</a> - <font size=-1>collision detection between two sprites, using circles.</font></td><td>collision detection between two sprites, using circles.</td></tr>
63
 
  <tr><td><a href="sprite.html#pygame.sprite.collide_circle_ratio">pygame.sprite.collide_circle_ratio</a> - <font size=-1>collision detection between two sprites, using circles scaled to a ratio.</font></td><td>collision detection between two sprites, using circles scaled to a ratio.</td></tr>
64
 
  <tr><td><a href="sprite.html#pygame.sprite.collide_mask">pygame.sprite.collide_mask</a> - <font size=-1>collision detection between two sprites, using masks.</font></td><td>collision detection between two sprites, using masks.</td></tr>
65
 
  <tr><td><a href="sprite.html#pygame.sprite.groupcollide">pygame.sprite.groupcollide</a> - <font size=-1>find all Sprites that collide between two Groups</font></td><td>find all Sprites that collide between two Groups</td></tr>
66
 
  <tr><td><a href="sprite.html#pygame.sprite.spritecollideany">pygame.sprite.spritecollideany</a> - <font size=-1>simple test if a Sprite intersects anything in a Group</font></td><td>simple test if a Sprite intersects anything in a Group</td></tr>
67
 
  <tr><td>None</td><td></td></tr>
68
 
</table></small></ul>
69
 
<p>This module contains several simple classes to be used within games. There is the main Sprite class and several Group classes that contain Sprites. The use of these classes is entirely optional when using Pygame. The classes are fairly lightweight and only provide a starting place for the code that is common to most games. </p>
70
 
<p>The Sprite class is intended to be used as a base class for the different types of objects in the game. There is also a base Group class that simply stores sprites. <tt>A</tt> game could create new types of Group classes that operate on specially customized Sprite instances they contain. </p>
71
 
<p>The basic Sprite class can draw the Sprites it contains to a Surface. The <tt><a href="sprite.html#Group.draw">Group.draw</a> - <font size=-1>blit the Sprite images</font></tt> method requires that each Sprite have a <tt>Surface.image</tt> attribute and a <tt>Surface.rect</tt>. The <tt><a href="sprite.html#Group.clear">Group.clear</a> - <font size=-1>draw a background over the Sprites</font></tt> method requires these same attributes, and can be used to erase all the Sprites with background. There are also more advanced Groups: <tt><a href="sprite.html#pygame.sprite.RenderUpdates">pygame.sprite.RenderUpdates</a> - <font size=-1>Group class that tracks dirty updates</font></tt> and <tt><a href="sprite.html#pygame.sprite.OrderedUpdates">pygame.sprite.OrderedUpdates</a> - <font size=-1>RenderUpdates class that draws Sprites in order of addition</font></tt>. </p>
72
 
<p>Lastly, this module contains several collision functions. These help find sprites inside multiple groups that have intersecting bounding rectangles. To find the collisions, the Sprites are required to have a <tt>Surface.rect</tt> attribute assigned. </p>
73
 
<p>The groups are designed for high efficiency in removing and adding Sprites to them. They also allow cheap testing to see if a Sprite already exists in a Group. <tt>A</tt> given Sprite can exist in any number of groups. <tt>A</tt> game could use some groups to control object rendering, and a completely separate set of groups to control interaction or player movement. Instead of adding type attributes or bools to a derived Sprite class, consider keeping the Sprites inside organized Groups. This will allow for easier lookup later in the game. </p>
74
 
<p>Sprites and Groups manage their relationships with the add() and remove() methods. These methods can accept a single or multiple targets for membership. The default initializers for these classes also takes a single or list of targets for initial membership. It is safe to repeatedly add and remove the same Sprite from a Group. </p>
75
 
<p>While it is possible to design sprite and group classes that don't derive from the Sprite and AbstractGroup classes below, it is strongly recommended that you extend those when you add a Sprite or Group class. </p>
76
 
<p>Sprites are not thread safe. So lock them yourself if using threads. </p>
77
 
<!--COMMENTS:pygame.sprite--> &nbsp;<br> 
78
 
 
79
 
 
80
 
<a name="pygame.sprite.Sprite">
81
 
<big><b>pygame.sprite.Sprite</big></b><br><ul>
82
 
  <i>simple base class for visible game objects</i><br>
83
 
  <tt>pygame.sprite.Sprite(*groups): return Sprite</tt><br>
84
 
<ul><small><table>
85
 
  <tr><td><a href="sprite.html#Sprite.update">Sprite.update</a> - <font size=-1>method to control sprite behavior</font></td><td>method to control sprite behavior</td></tr>
86
 
  <tr><td><a href="sprite.html#Sprite.add">Sprite.add</a> - <font size=-1>add the sprite to groups</font></td><td>add the sprite to groups</td></tr>
87
 
  <tr><td><a href="sprite.html#Sprite.remove">Sprite.remove</a> - <font size=-1>remove the sprite from groups</font></td><td>remove the sprite from groups</td></tr>
88
 
  <tr><td><a href="sprite.html#Sprite.kill">Sprite.kill</a> - <font size=-1>remove the Sprite from all Groups</font></td><td>remove the Sprite from all Groups</td></tr>
89
 
  <tr><td><a href="sprite.html#Sprite.alive">Sprite.alive</a> - <font size=-1>does the sprite belong to any groups</font></td><td>does the sprite belong to any groups</td></tr>
90
 
  <tr><td><a href="sprite.html#Sprite.groups">Sprite.groups</a> - <font size=-1>list of Groups that contain this Sprite</font></td><td>list of Groups that contain this Sprite</td></tr>
91
 
</table></small></ul>
92
 
<p>The base class for visible game objects. Derived classes will want to override the <tt><a href="sprite.html#Sprite.update">Sprite.update</a> - <font size=-1>method to control sprite behavior</font></tt> and assign a <tt>Sprite.image</tt> and <tt>Sprite.rect</tt> attributes. The initializer can accept any number of Group instances to be added to. </p>
93
 
<p>When subclassing the Sprite, be sure to call the base initializer before adding the Sprite to Groups. </p>
94
 
<!--COMMENTS:pygame.sprite.Sprite--> &nbsp;<br> 
95
 
 
96
 
 
97
 
<a name="Sprite.update">
98
 
<big><b>Sprite.update</big></b><br><ul>
99
 
  <i>method to control sprite behavior</i><br>
100
 
  <tt>Sprite.update(*args):</tt><br>
101
 
<p>The default implementation of this method does nothing; it's just a convenient "hook" that you can override. This method is called by <tt><a href="sprite.html#Group.update">Group.update</a> - <font size=-1>call the update method on contained Sprites</font></tt> with whatever arguments you give it. </p>
102
 
<p>There is no need to use this method if not using the convenience method by the same name in the Group class. </p>
103
 
<!--COMMENTS:Sprite.update--> &nbsp;<br> 
104
 
<br></ul>
105
 
 
106
 
 
107
 
<a name="Sprite.add">
108
 
<big><b>Sprite.add</big></b><br><ul>
109
 
  <i>add the sprite to groups</i><br>
110
 
  <tt>Sprite.add(*groups): return None</tt><br>
111
 
<p>Any number of Group instances can be passed as arguments. The Sprite will be added to the Groups it is not already a member of. </p>
112
 
<!--COMMENTS:Sprite.add--> &nbsp;<br> 
113
 
<br></ul>
114
 
 
115
 
 
116
 
<a name="Sprite.remove">
117
 
<big><b>Sprite.remove</big></b><br><ul>
118
 
  <i>remove the sprite from groups</i><br>
119
 
  <tt>Sprite.remove(*groups): return None</tt><br>
120
 
<p>Any number of Group instances can be passed as arguments. The Sprite will be removed from the Groups it is currently a member of. </p>
121
 
<!--COMMENTS:Sprite.remove--> &nbsp;<br> 
122
 
<br></ul>
123
 
 
124
 
 
125
 
<a name="Sprite.kill">
126
 
<big><b>Sprite.kill</big></b><br><ul>
127
 
  <i>remove the Sprite from all Groups</i><br>
128
 
  <tt>Sprite.kill(): return None</tt><br>
129
 
<p>The Sprite is removed from all the Groups that contain it. This won't change anything about the state of the Sprite. It is possible to continue to use the Sprite after this method has been called, including adding it to Groups. </p>
130
 
<!--COMMENTS:Sprite.kill--> &nbsp;<br> 
131
 
<br></ul>
132
 
 
133
 
 
134
 
<a name="Sprite.alive">
135
 
<big><b>Sprite.alive</big></b><br><ul>
136
 
  <i>does the sprite belong to any groups</i><br>
137
 
  <tt>Sprite.alive(): return bool</tt><br>
138
 
<p>Returns True when the Sprite belongs to one or more Groups. </p>
139
 
<!--COMMENTS:Sprite.alive--> &nbsp;<br> 
140
 
<br></ul>
141
 
 
142
 
 
143
 
<a name="Sprite.groups">
144
 
<big><b>Sprite.groups</big></b><br><ul>
145
 
  <i>list of Groups that contain this Sprite</i><br>
146
 
  <tt>Sprite.groups(): return group_list</tt><br>
147
 
<p>Return a list of all the Groups that contain this Sprite. </p>
148
 
<!--COMMENTS:Sprite.groups--> &nbsp;<br> 
149
 
<br></ul>
150
 
<br></ul>
151
 
 
152
 
 
153
 
<a name="pygame.sprite.DirtySprite">
154
 
<big><b>pygame.sprite.DirtySprite</big></b><br><ul>
155
 
  <i>a more featureful subclass of Sprite with more attributes</i><br>
156
 
  <tt>pygame.sprite.DirtySprite(*groups): return DirtySprite</tt><br>
157
 
<ul><small><table>
158
 
  <tr><td>None</td><td></td></tr>
159
 
</table></small></ul>
160
 
<p>Extra DirtySprite attributes with their default values: </p>
161
 
<p>dirty = 1 </p>
162
 
<pre>    if set to 1, it is repainted and then set to 0 again
163
 
    if set to 2 then it is always dirty ( repainted each frame,
164
 
    flag is not reset)
165
 
    0 means that it is not dirty and therefor not repainted again
166
 
</pre><p>blendmode = 0 </p>
167
 
<pre>    its the special_flags argument of blit, blendmodes
168
 
</pre><p>source_rect = None </p>
169
 
<pre>    source rect to use, remember that it is relative to
170
 
    topleft (0,0) of self.image
171
 
</pre><p>visible = 1 </p>
172
 
<pre>    normally 1, if set to 0 it will not be repainted
173
 
    (you must set it dirty too to be erased from screen)
174
 
</pre><p>layer = 0 </p>
175
 
<pre>    (READONLY value, it is read when adding it to the
176
 
    LayeredRenderGroup, for details see doc of LayeredRenderGroup)
177
 
</pre>
178
 
<!--COMMENTS:pygame.sprite.DirtySprite--> &nbsp;<br> 
179
 
 
180
 
 
181
 
<a name="">
182
 
<big><b></big></b><br><ul>
183
 
 &nbsp;<br> 
184
 
<!--COMMENTS:--> &nbsp;<br> 
185
 
<br></ul>
186
 
<br></ul>
187
 
 
188
 
 
189
 
<a name="pygame.sprite.Group">
190
 
<big><b>pygame.sprite.Group</big></b><br><ul>
191
 
  <i>container class for many Sprites</i><br>
192
 
  <tt>pygame.sprite.Group(*sprites): return Group</tt><br>
193
 
<ul><small><table>
194
 
  <tr><td><a href="sprite.html#Group.sprites">Group.sprites</a> - <font size=-1>list of the Sprites this Group contains</font></td><td>list of the Sprites this Group contains</td></tr>
195
 
  <tr><td><a href="sprite.html#Group.copy">Group.copy</a> - <font size=-1>duplicate the Group</font></td><td>duplicate the Group</td></tr>
196
 
  <tr><td><a href="sprite.html#Group.add">Group.add</a> - <font size=-1>add Sprites to this Group</font></td><td>add Sprites to this Group</td></tr>
197
 
  <tr><td><a href="sprite.html#Group.remove">Group.remove</a> - <font size=-1>remove Sprites from the Group</font></td><td>remove Sprites from the Group</td></tr>
198
 
  <tr><td><a href="sprite.html#Group.has">Group.has</a> - <font size=-1>test if a Group contains Sprites</font></td><td>test if a Group contains Sprites</td></tr>
199
 
  <tr><td><a href="sprite.html#Group.update">Group.update</a> - <font size=-1>call the update method on contained Sprites</font></td><td>call the update method on contained Sprites</td></tr>
200
 
  <tr><td><a href="sprite.html#Group.draw">Group.draw</a> - <font size=-1>blit the Sprite images</font></td><td>blit the Sprite images</td></tr>
201
 
  <tr><td><a href="sprite.html#Group.clear">Group.clear</a> - <font size=-1>draw a background over the Sprites</font></td><td>draw a background over the Sprites</td></tr>
202
 
  <tr><td><a href="sprite.html#Group.empty">Group.empty</a> - <font size=-1>remove all Sprites</font></td><td>remove all Sprites</td></tr>
203
 
</table></small></ul>
204
 
<p><tt>A</tt> simple container for Sprite objects. This class can be inherited to create containers with more specific behaviors. The constructor takes any number of Sprite arguments to add to the Group. The group supports the following standard Python operations: </p>
205
 
<pre>    in      test if a Sprite is contained
206
 
    len     the number of Sprites contained
207
 
    bool test if any Sprites are contained
208
 
    iter    iterate through all the Sprites
209
 
</pre><p>The Sprites in the Group are not ordered, so drawing and iterating the Sprites is in no particular order. </p>
210
 
<!--COMMENTS:pygame.sprite.Group--> &nbsp;<br> 
211
 
 
212
 
 
213
 
<a name="Group.sprites">
214
 
<big><b>Group.sprites</big></b><br><ul>
215
 
  <i>list of the Sprites this Group contains</i><br>
216
 
  <tt>Group.sprites(): return sprite_list</tt><br>
217
 
<p>Return a list of all the Sprites this group contains. You can also get an iterator from the group, but you cannot iterator over a Group while modifying it. </p>
218
 
<!--COMMENTS:Group.sprites--> &nbsp;<br> 
219
 
<br></ul>
220
 
 
221
 
 
222
 
<a name="Group.copy">
223
 
<big><b>Group.copy</big></b><br><ul>
224
 
  <i>duplicate the Group</i><br>
225
 
  <tt>Group.copy(): return Group</tt><br>
226
 
<p>Creates a new Group with all the same Sprites as the original. If you have subclassed Group, the new object will have the same (sub-)class as the original. This only works if the derived class's constructor takes the same arguments as the Group class's. </p>
227
 
<!--COMMENTS:Group.copy--> &nbsp;<br> 
228
 
<br></ul>
229
 
 
230
 
 
231
 
<a name="Group.add">
232
 
<big><b>Group.add</big></b><br><ul>
233
 
  <i>add Sprites to this Group</i><br>
234
 
  <tt>Group.add(*sprites): return None</tt><br>
235
 
<p>Add any number of Sprites to this Group. This will only add Sprites that are not already members of the Group. </p>
236
 
<p>Each sprite argument can also be a iterator containing Sprites. </p>
237
 
<!--COMMENTS:Group.add--> &nbsp;<br> 
238
 
<br></ul>
239
 
 
240
 
 
241
 
<a name="Group.remove">
242
 
<big><b>Group.remove</big></b><br><ul>
243
 
  <i>remove Sprites from the Group</i><br>
244
 
  <tt>Group.remove(*sprites): return None</tt><br>
245
 
<p>Remove any number of Sprites from the Group. This will only remove Sprites that are already members of the Group. </p>
246
 
<p>Each sprite argument can also be a iterator containing Sprites. </p>
247
 
<!--COMMENTS:Group.remove--> &nbsp;<br> 
248
 
<br></ul>
249
 
 
250
 
 
251
 
<a name="Group.has">
252
 
<big><b>Group.has</big></b><br><ul>
253
 
  <i>test if a Group contains Sprites</i><br>
254
 
  <tt>Group.has(*sprites): return None</tt><br>
255
 
<p>Return True if the Group contains all of the given sprites. This is similar to using the "in" operator on the Group ("if sprite in group: <tt>...")</tt>, which tests if a single Sprite belongs to a Group. </p>
256
 
<p>Each sprite argument can also be a iterator containing Sprites. </p>
257
 
<!--COMMENTS:Group.has--> &nbsp;<br> 
258
 
<br></ul>
259
 
 
260
 
 
261
 
<a name="Group.update">
262
 
<big><b>Group.update</big></b><br><ul>
263
 
  <i>call the update method on contained Sprites</i><br>
264
 
  <tt>Group.update(*args): return None</tt><br>
265
 
<p>Calls the update() method on all Sprites in the Group. The base Sprite class has an update method that takes any number of arguments and does nothing. The arguments passed to <tt><a href="sprite.html#Group.update">Group.update</a> - <font size=-1>call the update method on contained Sprites</font></tt> will be passed to each Sprite. </p>
266
 
<p>There is no way to get the return value from the <tt><a href="sprite.html#Sprite.update">Sprite.update</a> - <font size=-1>method to control sprite behavior</font></tt> methods. </p>
267
 
<!--COMMENTS:Group.update--> &nbsp;<br> 
268
 
<br></ul>
269
 
 
270
 
 
271
 
<a name="Group.draw">
272
 
<big><b>Group.draw</big></b><br><ul>
273
 
  <i>blit the Sprite images</i><br>
274
 
  <tt>Group.draw(Surface): return None</tt><br>
275
 
<p>Draws the contained Sprites to the Surface argument. This uses the <tt>Sprite.image</tt> attribute for the source surface, and <tt>Sprite.rect</tt> for the position. </p>
276
 
<p>The Group does not keep sprites in any order, so the draw order is arbitrary. </p>
277
 
<!--COMMENTS:Group.draw--> &nbsp;<br> 
278
 
<br></ul>
279
 
 
280
 
 
281
 
<a name="Group.clear">
282
 
<big><b>Group.clear</big></b><br><ul>
283
 
  <i>draw a background over the Sprites</i><br>
284
 
  <tt>Group.clear(Surface_dest, background): return None</tt><br>
285
 
<p>Erases the Sprites used in the last <tt><a href="sprite.html#Group.draw">Group.draw</a> - <font size=-1>blit the Sprite images</font></tt> call. The destination Surface is cleared by filling the drawn Sprite positions with the background. </p>
286
 
<p>The background is usually a Surface image the same dimensions as the destination Surface. However, it can also be a callback function that takes two arguments; the destination Surface and an area to clear. The background callback function will be called several times each clear. </p>
287
 
<p>Here is an example callback that will clear the Sprites with solid red: </p>
288
 
<pre>    def clear_callback(surf, rect):
289
 
        color = 255, 0, 0
290
 
        surf.fill(color, rect)
291
 
</pre>
292
 
<!--COMMENTS:Group.clear--> &nbsp;<br> 
293
 
<br></ul>
294
 
 
295
 
 
296
 
<a name="Group.empty">
297
 
<big><b>Group.empty</big></b><br><ul>
298
 
  <i>remove all Sprites</i><br>
299
 
  <tt>Group.empty(): return None</tt><br>
300
 
<p>Removes all Sprites from this Group. </p>
301
 
<!--COMMENTS:Group.empty--> &nbsp;<br> 
302
 
<br></ul>
303
 
<br></ul>
304
 
 
305
 
 
306
 
<a name="pygame.sprite.RenderUpdates">
307
 
<big><b>pygame.sprite.RenderUpdates</big></b><br><ul>
308
 
  <i>Group class that tracks dirty updates</i><br>
309
 
  <tt>pygame.sprite.RenderUpdates(*sprites): return RenderUpdates</tt><br>
310
 
<ul><small><table>
311
 
  <tr><td><a href="sprite.html#RenderUpdates.draw">RenderUpdates.draw</a> - <font size=-1>blit the Sprite images and track changed areas</font></td><td>blit the Sprite images and track changed areas</td></tr>
312
 
</table></small></ul>
313
 
<p>This class is derived from <tt><a href="sprite.html#pygame.sprite.Group">pygame.sprite.Group</a> - <font size=-1>container class for many Sprites</font></tt>. It has an extended draw() method that tracks the changed areas of the screen. </p>
314
 
<!--COMMENTS:pygame.sprite.RenderUpdates--> &nbsp;<br> 
315
 
 
316
 
 
317
 
<a name="RenderUpdates.draw">
318
 
<big><b>RenderUpdates.draw</big></b><br><ul>
319
 
  <i>blit the Sprite images and track changed areas</i><br>
320
 
  <tt>RenderUpdates.draw(surface): return Rect_list</tt><br>
321
 
<p>Draws all the Sprites to the surface, the same as <tt><a href="sprite.html#Group.draw">Group.draw</a> - <font size=-1>blit the Sprite images</font></tt>. This method also returns a list of Rectangular areas on the screen that have been changed. The returned changes include areas of the screen that have been affected by previous <tt><a href="sprite.html#Group.clear">Group.clear</a> - <font size=-1>draw a background over the Sprites</font></tt> calls. </p>
322
 
<p>The returned Rect list should be passed to <tt><a href="display.html#pygame.display.update">pygame.display.update</a> - <font size=-1>update portions of the screen for software displays</font></tt>. This will help performance on software driven display modes. This type of updating is usually only helpful on destinations with non-animating backgrounds. </p>
323
 
<!--COMMENTS:RenderUpdates.draw--> &nbsp;<br> 
324
 
<br></ul>
325
 
<br></ul>
326
 
 
327
 
 
328
 
<a name="pygame.sprite.OrderedUpdates">
329
 
<big><b>pygame.sprite.OrderedUpdates</big></b><br><ul>
330
 
  <i>RenderUpdates class that draws Sprites in order of addition</i><br>
331
 
  <tt>pygame.sprite.OrderedUpdates(*spites): return OrderedUpdates</tt><br>
332
 
<p>This class derives from <tt><a href="sprite.html#pygame.sprite.RenderUpdates">pygame.sprite.RenderUpdates</a> - <font size=-1>Group class that tracks dirty updates</font></tt>. It maintains the order in which the Sprites were added to the Group for rendering. This makes adding and removing Sprites from the Group a little slower than regular Groups. </p>
333
 
<!--COMMENTS:pygame.sprite.OrderedUpdates--> &nbsp;<br> 
334
 
<br></ul>
335
 
 
336
 
 
337
 
<a name="pygame.sprite.LayeredUpdates">
338
 
<big><b>pygame.sprite.LayeredUpdates</big></b><br><ul>
339
 
  <i>LayeredUpdates Group handles layers, that draws like OrderedUpdates.</i><br>
340
 
  <tt>pygame.sprite.LayeredUpdates(*spites, **kwargs): return LayeredUpdates</tt><br>
341
 
<ul><small><table>
342
 
  <tr><td><a href="sprite.html#LayeredUpdates.add">LayeredUpdates.add</a> - <font size=-1>add a sprite or sequence of sprites to a group</font></td><td>add a sprite or sequence of sprites to a group</td></tr>
343
 
  <tr><td><a href="sprite.html#LayeredUpdates.sprites">LayeredUpdates.sprites</a> - <font size=-1>returns a ordered list of sprites (first back, last top).</font></td><td>returns a ordered list of sprites (first back, last top).</td></tr>
344
 
  <tr><td><a href="sprite.html#LayeredUpdates.draw">LayeredUpdates.draw</a> - <font size=-1>draw all sprites in the right order onto the passed surface.</font></td><td>draw all sprites in the right order onto the passed surface.</td></tr>
345
 
  <tr><td><a href="sprite.html#LayeredUpdates.get_sprites_at">LayeredUpdates.get_sprites_at</a> - <font size=-1>returns a list with all sprites at that position.</font></td><td>returns a list with all sprites at that position.</td></tr>
346
 
  <tr><td><a href="sprite.html#LayeredUpdates.get_sprite">LayeredUpdates.get_sprite</a> - <font size=-1>returns the sprite at the index idx from the groups sprites</font></td><td>returns the sprite at the index idx from the groups sprites</td></tr>
347
 
  <tr><td><a href="sprite.html#LayeredUpdates.remove_sprites_of_layer">LayeredUpdates.remove_sprites_of_layer</a> - <font size=-1>removes all sprites from a layer and returns them as a list.</font></td><td>removes all sprites from a layer and returns them as a list.</td></tr>
348
 
  <tr><td><a href="sprite.html#LayeredUpdates.layers">LayeredUpdates.layers</a> - <font size=-1>returns a list of layers defined (unique), sorted from botton up.</font></td><td>returns a list of layers defined (unique), sorted from botton up.</td></tr>
349
 
  <tr><td><a href="sprite.html#LayeredUpdates.change_layer">LayeredUpdates.change_layer</a> - <font size=-1>changes the layer of the sprite</font></td><td>changes the layer of the sprite</td></tr>
350
 
  <tr><td><a href="sprite.html#LayeredUpdates.get_layer_of_sprite">LayeredUpdates.get_layer_of_sprite</a> - <font size=-1>returns the layer that sprite is currently in.</font></td><td>returns the layer that sprite is currently in.</td></tr>
351
 
  <tr><td><a href="sprite.html#LayeredUpdates.get_top_layer">LayeredUpdates.get_top_layer</a> - <font size=-1>returns the top layer</font></td><td>returns the top layer</td></tr>
352
 
  <tr><td><a href="sprite.html#LayeredUpdates.get_bottom_layer">LayeredUpdates.get_bottom_layer</a> - <font size=-1>returns the bottom layer</font></td><td>returns the bottom layer</td></tr>
353
 
  <tr><td><a href="sprite.html#LayeredUpdates.move_to_front">LayeredUpdates.move_to_front</a> - <font size=-1>brings the sprite to front layer</font></td><td>brings the sprite to front layer</td></tr>
354
 
  <tr><td><a href="sprite.html#LayeredUpdates.move_to_back">LayeredUpdates.move_to_back</a> - <font size=-1>moves the sprite to the bottom layer</font></td><td>moves the sprite to the bottom layer</td></tr>
355
 
  <tr><td><a href="sprite.html#LayeredUpdates.get_top_sprite">LayeredUpdates.get_top_sprite</a> - <font size=-1>returns the topmost sprite</font></td><td>returns the topmost sprite</td></tr>
356
 
  <tr><td><a href="sprite.html#LayeredUpdates.get_sprites_from_layer">LayeredUpdates.get_sprites_from_layer</a> - <font size=-1>returns all sprites from a layer, ordered by how they where added</font></td><td>returns all sprites from a layer, ordered by how they where added</td></tr>
357
 
  <tr><td><a href="sprite.html#LayeredUpdates.switch_layer">LayeredUpdates.switch_layer</a> - <font size=-1>switches the sprites from layer1 to layer2</font></td><td>switches the sprites from layer1 to layer2</td></tr>
358
 
</table></small></ul>
359
 
<p>This group is fully compatible with <tt>pygame.sprite.Sprite</tt>. </p>
360
 
<p>You can set the default layer through kwargs using 'default_layer' and an integer for the layer. The default layer is 0. </p>
361
 
<p>If the sprite you add has an attribute layer then that layer will be used. If the **kwarg contains 'layer' then the sprites passed will be added to that layer (overriding the <tt>sprite.layer</tt> attribute). If neither sprite has attribute layer nor **kwarg then the default layer is used to add the sprites. </p>
362
 
<p>New in pygame <tt>1.8.0</tt> </p>
363
 
<!--COMMENTS:pygame.sprite.LayeredUpdates--> &nbsp;<br> 
364
 
 
365
 
 
366
 
<a name="LayeredUpdates.add">
367
 
<big><b>LayeredUpdates.add</big></b><br><ul>
368
 
  <i>add a sprite or sequence of sprites to a group</i><br>
369
 
  <tt>LayeredUpdates.add(*sprites, **kwargs): return None</tt><br>
370
 
<p>If the sprite(s) have an attribute layer then that is used for the layer. If **kwargs contains 'layer' then the sprite(s) will be added to that argument (overriding the sprite layer attribute). If neither is passed then the sprite(s) will be added to the default layer. </p>
371
 
<!--COMMENTS:LayeredUpdates.add--> &nbsp;<br> 
372
 
<br></ul>
373
 
 
374
 
 
375
 
<a name="LayeredUpdates.sprites">
376
 
<big><b>LayeredUpdates.sprites</big></b><br><ul>
377
 
  <i>returns a ordered list of sprites (first back, last top).</i><br>
378
 
  <tt>LayeredUpdates.sprites(): return sprites</tt><br>
379
 
 &nbsp;<br> 
380
 
<!--COMMENTS:LayeredUpdates.sprites--> &nbsp;<br> 
381
 
<br></ul>
382
 
 
383
 
 
384
 
<a name="LayeredUpdates.draw">
385
 
<big><b>LayeredUpdates.draw</big></b><br><ul>
386
 
  <i>draw all sprites in the right order onto the passed surface.</i><br>
387
 
  <tt>LayeredUpdates.draw(surface): return Rect_list</tt><br>
388
 
 &nbsp;<br> 
389
 
<!--COMMENTS:LayeredUpdates.draw--> &nbsp;<br> 
390
 
<br></ul>
391
 
 
392
 
 
393
 
<a name="LayeredUpdates.get_sprites_at">
394
 
<big><b>LayeredUpdates.get_sprites_at</big></b><br><ul>
395
 
  <i>returns a list with all sprites at that position.</i><br>
396
 
  <tt>LayeredUpdates.get_sprites_at(pos): return colliding_sprites</tt><br>
397
 
<p>Bottom sprites first, top last. </p>
398
 
<!--COMMENTS:LayeredUpdates.get_sprites_at--> &nbsp;<br> 
399
 
<br></ul>
400
 
 
401
 
 
402
 
<a name="LayeredUpdates.get_sprite">
403
 
<big><b>LayeredUpdates.get_sprite</big></b><br><ul>
404
 
  <i>returns the sprite at the index idx from the groups sprites</i><br>
405
 
  <tt>LayeredUpdates.get_sprite(idx): return sprite</tt><br>
406
 
<p>Raises IndexOutOfBounds if the idx is not within range. </p>
407
 
<!--COMMENTS:LayeredUpdates.get_sprite--> &nbsp;<br> 
408
 
<br></ul>
409
 
 
410
 
 
411
 
<a name="LayeredUpdates.remove_sprites_of_layer">
412
 
<big><b>LayeredUpdates.remove_sprites_of_layer</big></b><br><ul>
413
 
  <i>removes all sprites from a layer and returns them as a list.</i><br>
414
 
  <tt>LayeredUpdates.remove_sprites_of_layer(layer_nr): return sprites</tt><br>
415
 
 &nbsp;<br> 
416
 
<!--COMMENTS:LayeredUpdates.remove_sprites_of_layer--> &nbsp;<br> 
417
 
<br></ul>
418
 
 
419
 
 
420
 
<a name="LayeredUpdates.layers">
421
 
<big><b>LayeredUpdates.layers</big></b><br><ul>
422
 
  <i>returns a list of layers defined (unique), sorted from botton up.</i><br>
423
 
  <tt>LayeredUpdates.layers(): return layers</tt><br>
424
 
 &nbsp;<br> 
425
 
<!--COMMENTS:LayeredUpdates.layers--> &nbsp;<br> 
426
 
<br></ul>
427
 
 
428
 
 
429
 
<a name="LayeredUpdates.change_layer">
430
 
<big><b>LayeredUpdates.change_layer</big></b><br><ul>
431
 
  <i>changes the layer of the sprite</i><br>
432
 
  <tt>LayeredUpdates.change_layer(sprite, new_layer): return None</tt><br>
433
 
<p>sprite must have been added to the renderer. It is not checked. </p>
434
 
<!--COMMENTS:LayeredUpdates.change_layer--> &nbsp;<br> 
435
 
<br></ul>
436
 
 
437
 
 
438
 
<a name="LayeredUpdates.get_layer_of_sprite">
439
 
<big><b>LayeredUpdates.get_layer_of_sprite</big></b><br><ul>
440
 
  <i>returns the layer that sprite is currently in.</i><br>
441
 
  <tt>LayeredUpdates.get_layer_of_sprite(sprite): return layer</tt><br>
442
 
<p>If the sprite is not found then it will return the default layer. </p>
443
 
<!--COMMENTS:LayeredUpdates.get_layer_of_sprite--> &nbsp;<br> 
444
 
<br></ul>
445
 
 
446
 
 
447
 
<a name="LayeredUpdates.get_top_layer">
448
 
<big><b>LayeredUpdates.get_top_layer</big></b><br><ul>
449
 
  <i>returns the top layer</i><br>
450
 
  <tt>LayeredUpdates.get_top_layer(): return layer</tt><br>
451
 
 &nbsp;<br> 
452
 
<!--COMMENTS:LayeredUpdates.get_top_layer--> &nbsp;<br> 
453
 
<br></ul>
454
 
 
455
 
 
456
 
<a name="LayeredUpdates.get_bottom_layer">
457
 
<big><b>LayeredUpdates.get_bottom_layer</big></b><br><ul>
458
 
  <i>returns the bottom layer</i><br>
459
 
  <tt>LayeredUpdates.get_bottom_layer(): return layer</tt><br>
460
 
 &nbsp;<br> 
461
 
<!--COMMENTS:LayeredUpdates.get_bottom_layer--> &nbsp;<br> 
462
 
<br></ul>
463
 
 
464
 
 
465
 
<a name="LayeredUpdates.move_to_front">
466
 
<big><b>LayeredUpdates.move_to_front</big></b><br><ul>
467
 
  <i>brings the sprite to front layer</i><br>
468
 
  <tt>LayeredUpdates.move_to_front(sprite): return None</tt><br>
469
 
<p>Brings the sprite to front, changing sprite layer to topmost layer (added at the end of that layer). </p>
470
 
<!--COMMENTS:LayeredUpdates.move_to_front--> &nbsp;<br> 
471
 
<br></ul>
472
 
 
473
 
 
474
 
<a name="LayeredUpdates.move_to_back">
475
 
<big><b>LayeredUpdates.move_to_back</big></b><br><ul>
476
 
  <i>moves the sprite to the bottom layer</i><br>
477
 
  <tt>LayeredUpdates.move_to_back(sprite): return None</tt><br>
478
 
<p>Moves the sprite to the bottom layer, moving it behind all other layers and adding one additional layer. </p>
479
 
<!--COMMENTS:LayeredUpdates.move_to_back--> &nbsp;<br> 
480
 
<br></ul>
481
 
 
482
 
 
483
 
<a name="LayeredUpdates.get_top_sprite">
484
 
<big><b>LayeredUpdates.get_top_sprite</big></b><br><ul>
485
 
  <i>returns the topmost sprite</i><br>
486
 
  <tt>LayeredUpdates.get_top_sprite(): return Sprite</tt><br>
487
 
 &nbsp;<br> 
488
 
<!--COMMENTS:LayeredUpdates.get_top_sprite--> &nbsp;<br> 
489
 
<br></ul>
490
 
 
491
 
 
492
 
<a name="LayeredUpdates.get_sprites_from_layer">
493
 
<big><b>LayeredUpdates.get_sprites_from_layer</big></b><br><ul>
494
 
  <i>returns all sprites from a layer, ordered by how they where added</i><br>
495
 
  <tt>LayeredUpdates.get_sprites_from_layer(layer): return sprites</tt><br>
496
 
<p>Returns all sprites from a layer, ordered by how they where added. It uses linear search and the sprites are not removed from layer. </p>
497
 
<!--COMMENTS:LayeredUpdates.get_sprites_from_layer--> &nbsp;<br> 
498
 
<br></ul>
499
 
 
500
 
 
501
 
<a name="LayeredUpdates.switch_layer">
502
 
<big><b>LayeredUpdates.switch_layer</big></b><br><ul>
503
 
  <i>switches the sprites from layer1 to layer2</i><br>
504
 
  <tt>LayeredUpdates.switch_layer(layer1_nr, layer2_nr): return None</tt><br>
505
 
<p>The layers number must exist, it is not checked. </p>
506
 
<!--COMMENTS:LayeredUpdates.switch_layer--> &nbsp;<br> 
507
 
<br></ul>
508
 
<br></ul>
509
 
 
510
 
 
511
 
<a name="pygame.sprite.LayeredDirty">
512
 
<big><b>pygame.sprite.LayeredDirty</big></b><br><ul>
513
 
  <i>LayeredDirty Group is for DirtySprites.  Subclasses LayeredUpdates.</i><br>
514
 
  <tt>pygame.sprite.LayeredDirty(*spites, **kwargs): return LayeredDirty</tt><br>
515
 
<ul><small><table>
516
 
  <tr><td><a href="sprite.html#LayeredDirty.draw">LayeredDirty.draw</a> - <font size=-1>draw all sprites in the right order onto the passed surface.</font></td><td>draw all sprites in the right order onto the passed surface.</td></tr>
517
 
  <tr><td><a href="sprite.html#LayeredDirty.clear">LayeredDirty.clear</a> - <font size=-1>used to set background</font></td><td>used to set background</td></tr>
518
 
  <tr><td><a href="sprite.html#LayeredDirty.repaint_rect">LayeredDirty.repaint_rect</a> - <font size=-1>repaints the given area</font></td><td>repaints the given area</td></tr>
519
 
  <tr><td><a href="sprite.html#LayeredDirty.set_clip">LayeredDirty.set_clip</a> - <font size=-1>clip the area where to draw. Just pass None (default) to reset the clip</font></td><td>clip the area where to draw. Just pass None (default) to reset the clip</td></tr>
520
 
  <tr><td><a href="sprite.html#LayeredDirty.get_clip">LayeredDirty.get_clip</a> - <font size=-1>clip the area where to draw. Just pass None (default) to reset the clip</font></td><td>clip the area where to draw. Just pass None (default) to reset the clip</td></tr>
521
 
  <tr><td><a href="sprite.html#LayeredDirty.change_layer">LayeredDirty.change_layer</a> - <font size=-1>changes the layer of the sprite</font></td><td>changes the layer of the sprite</td></tr>
522
 
  <tr><td><a href="sprite.html#LayeredDirty.set_timing_treshold">LayeredDirty.set_timing_treshold</a> - <font size=-1>sets the treshold in milliseconds</font></td><td>sets the treshold in milliseconds</td></tr>
523
 
</table></small></ul>
524
 
<p>This group requires <tt>pygame.sprite.DirtySprite</tt> or any sprite that has the following attributes: </p>
525
 
<pre>    image, rect, dirty, visible, blendmode (see doc of DirtySprite).
526
 
</pre><p>It uses the dirty flag technique and is therefore faster than the <tt>pygame.sprite.RenderUpdates</tt> if you have many static sprites. It also switches automatically between dirty rect update and full screen drawing, so you do no have to worry what would be faster. </p>
527
 
<p>Same as for the <tt>pygame.sprite.Group</tt>. You can specify some additional attributes through kwargs: </p>
528
 
<pre>    _use_update: True/False   default is False
529
 
    _default_layer: default layer where sprites without a layer are added.
530
 
    _time_threshold: treshold time for switching between dirty rect mode
531
 
        and fullscreen mode, defaults to 1000./80  == 1000./fps
532
 
</pre><p>New in pygame <tt>1.8.0</tt> </p>
533
 
<!--COMMENTS:pygame.sprite.LayeredDirty--> &nbsp;<br> 
534
 
 
535
 
 
536
 
<a name="LayeredDirty.draw">
537
 
<big><b>LayeredDirty.draw</big></b><br><ul>
538
 
  <i>draw all sprites in the right order onto the passed surface.</i><br>
539
 
  <tt>LayeredDirty.draw(surface, bgd=None): return Rect_list</tt><br>
540
 
<p>You can pass the background too. If a background is already set, then the bgd argument has no effect. </p>
541
 
<!--COMMENTS:LayeredDirty.draw--> &nbsp;<br> 
542
 
<br></ul>
543
 
 
544
 
 
545
 
<a name="LayeredDirty.clear">
546
 
<big><b>LayeredDirty.clear</big></b><br><ul>
547
 
  <i>used to set background</i><br>
548
 
  <tt>LayeredDirty.clear(surface, bgd): return None</tt><br>
549
 
 &nbsp;<br> 
550
 
<!--COMMENTS:LayeredDirty.clear--> &nbsp;<br> 
551
 
<br></ul>
552
 
 
553
 
 
554
 
<a name="LayeredDirty.repaint_rect">
555
 
<big><b>LayeredDirty.repaint_rect</big></b><br><ul>
556
 
  <i>repaints the given area</i><br>
557
 
  <tt>LayeredDirty.repaint_rect(screen_rect): return None</tt><br>
558
 
<p>screen_rect is in screencoordinates. </p>
559
 
<!--COMMENTS:LayeredDirty.repaint_rect--> &nbsp;<br> 
560
 
<br></ul>
561
 
 
562
 
 
563
 
<a name="LayeredDirty.set_clip">
564
 
<big><b>LayeredDirty.set_clip</big></b><br><ul>
565
 
  <i>clip the area where to draw. Just pass None (default) to reset the clip</i><br>
566
 
  <tt>LayeredDirty.set_clip(screen_rect=None): return None</tt><br>
567
 
 &nbsp;<br> 
568
 
<!--COMMENTS:LayeredDirty.set_clip--> &nbsp;<br> 
569
 
<br></ul>
570
 
 
571
 
 
572
 
<a name="LayeredDirty.get_clip">
573
 
<big><b>LayeredDirty.get_clip</big></b><br><ul>
574
 
  <i>clip the area where to draw. Just pass None (default) to reset the clip</i><br>
575
 
  <tt>LayeredDirty.get_clip(): return Rect</tt><br>
576
 
 &nbsp;<br> 
577
 
<!--COMMENTS:LayeredDirty.get_clip--> &nbsp;<br> 
578
 
<br></ul>
579
 
 
580
 
 
581
 
<a name="LayeredDirty.change_layer">
582
 
<big><b>LayeredDirty.change_layer</big></b><br><ul>
583
 
  <i>changes the layer of the sprite</i><br>
584
 
  <tt>change_layer(sprite, new_layer): return None</tt><br>
585
 
<p>sprite must have been added to the renderer. It is not checked. </p>
586
 
<!--COMMENTS:LayeredDirty.change_layer--> &nbsp;<br> 
587
 
<br></ul>
588
 
 
589
 
 
590
 
<a name="LayeredDirty.set_timing_treshold">
591
 
<big><b>LayeredDirty.set_timing_treshold</big></b><br><ul>
592
 
  <i>sets the treshold in milliseconds</i><br>
593
 
  <tt>set_timing_treshold(time_ms): return None</tt><br>
594
 
<p>Default is <tt>1000./80</tt> where 80 is the fps <tt>I</tt> want to switch to full screen mode. </p>
595
 
<!--COMMENTS:LayeredDirty.set_timing_treshold--> &nbsp;<br> 
596
 
<br></ul>
597
 
<br></ul>
598
 
 
599
 
 
600
 
<a name="pygame.sprite.GroupSingle">
601
 
<big><b>pygame.sprite.GroupSingle</big></b><br><ul>
602
 
  <i>Group container that holds a single Sprite</i><br>
603
 
  <tt>pygame.sprite.GroupSingle(sprite=None): return GroupSingle</tt><br>
604
 
<p>The GroupSingle container only holds a single Sprite. When a new Sprite is added, the old one is removed. </p>
605
 
<p>There is a special property, <tt>GroupSingle.sprite</tt>, that accesses the Sprite that this Group contains. It can be None when the Group is empty. The property can also be assigned to add a Sprite into the GroupSingle container. </p>
606
 
<!--COMMENTS:pygame.sprite.GroupSingle--> &nbsp;<br> 
607
 
<br></ul>
608
 
 
609
 
 
610
 
<a name="pygame.sprite.spritecollide">
611
 
<big><b>pygame.sprite.spritecollide</big></b><br><ul>
612
 
  <i>find Sprites in a Group that intersect another Sprite</i><br>
613
 
  <tt>pygame.sprite.spritecollide(sprite, group, dokill, collided = None): return Sprite_list</tt><br>
614
 
<p>Return a list containing all Sprites in a Group that intersect with another Sprite. Intersection is determined by comparing the <tt>Sprite.rect</tt> attribute of each Sprite. </p>
615
 
<p>The dokill argument is a bool. If set to True, all Sprites that collide will be removed from the Group. </p>
616
 
<p>The collided argument is a callback function used to calculate if two sprites are colliding. it should take two sprites as values, and return a bool value indicating if they are colliding. If collided is not passed, all sprites must have a "rect" value, which is a rectangle of the sprite area, which will be used to calculate the collision. </p>
617
 
<p>collided callables: </p>
618
 
<pre>    collide_rect, collide_rect_ratio, collide_circle,
619
 
    collide_circle_ratio, collide_mask
620
 
</pre>
621
 
<!--COMMENTS:pygame.sprite.spritecollide--> &nbsp;<br> 
622
 
<br></ul>
623
 
 
624
 
 
625
 
<a name="pygame.sprite.collide_rect">
626
 
<big><b>pygame.sprite.collide_rect</big></b><br><ul>
627
 
  <i>collision detection between two sprites, using rects.</i><br>
628
 
  <tt>pygame.sprite.collide_rect(left, right): return bool</tt><br>
629
 
<p>Tests for collision between two sprites. Uses the pygame rect colliderect function to calculate the collision. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" attributes. </p>
630
 
<p>New in pygame <tt>1.8.0</tt> </p>
631
 
<!--COMMENTS:pygame.sprite.collide_rect--> &nbsp;<br> 
632
 
<br></ul>
633
 
 
634
 
 
635
 
<a name="pygame.sprite.collide_rect_ratio">
636
 
<big><b>pygame.sprite.collide_rect_ratio</big></b><br><ul>
637
 
  <i>collision detection between two sprites, using rects scaled to a ratio.</i><br>
638
 
  <tt>pygame.sprite.collide_rect_ratio(ratio): return collided_callable</tt><br>
639
 
<p><tt>A</tt> callable class that checks for collisions between two sprites, using a scaled version of the sprites rects. </p>
640
 
<p>Is created with a ratio, the instance is then intended to be passed as a collided callback function to the *collide functions. </p>
641
 
<p><tt>A</tt> ratio is a floating point number - <tt>1.0</tt> is the same size, <tt>2.0</tt> is twice as big, and <tt>0.5</tt> is half the size. </p>
642
 
<p>New in pygame <tt>1.8.1</tt> </p>
643
 
<!--COMMENTS:pygame.sprite.collide_rect_ratio--> &nbsp;<br> 
644
 
<br></ul>
645
 
 
646
 
 
647
 
<a name="pygame.sprite.collide_circle">
648
 
<big><b>pygame.sprite.collide_circle</big></b><br><ul>
649
 
  <i>collision detection between two sprites, using circles.</i><br>
650
 
  <tt>pygame.sprite.collide_circle(left, right): return bool</tt><br>
651
 
<p>Tests for collision between two sprites, by testing to see if two circles centered on the sprites overlap. If the sprites have a "radius" attribute, that is used to create the circle, otherwise a circle is created that is big enough to completely enclose the sprites rect as given by the "rect" attribute. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" and an optional "radius" attribute. </p>
652
 
<p>New in pygame <tt>1.8.1</tt> </p>
653
 
<!--COMMENTS:pygame.sprite.collide_circle--> &nbsp;<br> 
654
 
<br></ul>
655
 
 
656
 
 
657
 
<a name="pygame.sprite.collide_circle_ratio">
658
 
<big><b>pygame.sprite.collide_circle_ratio</big></b><br><ul>
659
 
  <i>collision detection between two sprites, using circles scaled to a ratio.</i><br>
660
 
  <tt>pygame.sprite.collide_circle_ratio(ratio): return collided_callable</tt><br>
661
 
<p><tt>A</tt> callable class that checks for collisions between two sprites, using a scaled version of the sprites radius. </p>
662
 
<p>Is created with a floating point ratio, the instance is then intended to be passed as a collided callback function to the *collide functions. </p>
663
 
<p><tt>A</tt> ratio is a floating point number - <tt>1.0</tt> is the same size, <tt>2.0</tt> is twice as big, and <tt>0.5</tt> is half the size. </p>
664
 
<p>The created callable tests for collision between two sprites, by testing to see if two circles centered on the sprites overlap, after scaling the circles radius by the stored ratio. If the sprites have a "radius" attribute, that is used to create the circle, otherwise a circle is created that is big enough to completely enclose the sprites rect as given by the "rect" attribute. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" and an optional "radius" attribute. </p>
665
 
<p>New in pygame <tt>1.8.1</tt> </p>
666
 
<!--COMMENTS:pygame.sprite.collide_circle_ratio--> &nbsp;<br> 
667
 
<br></ul>
668
 
 
669
 
 
670
 
<a name="pygame.sprite.collide_mask">
671
 
<big><b>pygame.sprite.collide_mask</big></b><br><ul>
672
 
  <i>collision detection between two sprites, using masks.</i><br>
673
 
  <tt>pygame.sprite.collide_mask(SpriteLeft, SpriteRight): return bool</tt><br>
674
 
<p>Tests for collision between two sprites, by testing if thier bitmasks overlap. If the sprites have a "mask" attribute, that is used as the mask, otherwise a mask is created from the sprite image. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" and an optional "mask" attribute. </p>
675
 
<p>New in pygame <tt>1.8.0</tt> </p>
676
 
<!--COMMENTS:pygame.sprite.collide_mask--> &nbsp;<br> 
677
 
<br></ul>
678
 
 
679
 
 
680
 
<a name="pygame.sprite.groupcollide">
681
 
<big><b>pygame.sprite.groupcollide</big></b><br><ul>
682
 
  <i>find all Sprites that collide between two Groups</i><br>
683
 
  <tt>pygame.sprite.groupcollide(group1, group2, dokill1, dokill2): return Sprite_dict</tt><br>
684
 
<p>This will find intersections between all the Sprites in two groups. Intersection is determined by comparing the <tt>Sprite.rect</tt> attribute of each Sprite. </p>
685
 
<p>Every Sprite inside group1 is added to the return dictionary. The value for each item is the list of Sprites in group2 that intersect. </p>
686
 
<p>If either dokill argument is True, the intersecting Sprites will be removed from their respective Group. </p>
687
 
<!--COMMENTS:pygame.sprite.groupcollide--> &nbsp;<br> 
688
 
<br></ul>
689
 
 
690
 
 
691
 
<a name="pygame.sprite.spritecollideany">
692
 
<big><b>pygame.sprite.spritecollideany</big></b><br><ul>
693
 
  <i>simple test if a Sprite intersects anything in a Group</i><br>
694
 
  <tt>pygame.sprite.spritecollideany(sprite, group): return bool</tt><br>
695
 
<p>Test if the given Sprite intersects with any Sprites in a Group. Intersection is determined by comparing of the <tt>Sprite.rect</tt> attribute of each Sprite. </p>
696
 
<p>This collision test can be faster than <tt><a href="sprite.html#pygame.sprite.spritecollide">pygame.sprite.spritecollide</a> - <font size=-1>find Sprites in a Group that intersect another Sprite</font></tt> since it has less work to do. </p>
697
 
<!--COMMENTS:pygame.sprite.spritecollideany--> &nbsp;<br> 
698
 
<br></ul>
699
 
 
700
 
 
701
 
<a name="">
702
 
<big><b></big></b><br><ul>
703
 
 &nbsp;<br> 
704
 
<!--COMMENTS:--> &nbsp;<br> 
705
 
<br></ul>
706
 
<br></ul>
707
 
 
708
 
</body></html>
 
1
 
 
2
<html>
 
3
<title>sprite - Pygame Documentation</title>
 
4
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>
 
5
 
 
6
 
 
7
<table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%'>
 
8
<tr>
 
9
<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>
 
10
<td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center>
 
11
        ||&nbsp;
 
12
        <a href=http://www.pygame.org>Pygame Home</a> &nbsp;||&nbsp;
 
13
        <a href=../index.html>Help Contents</a> &nbsp;||
 
14
        <a href=index.html>Reference Index</a> &nbsp;||
 
15
        <br>&nbsp;<br>
 
16
        
 
17
<a href="camera.html">Camera</a>&nbsp;||&nbsp;
 
18
<a href="cdrom.html">Cdrom</a>&nbsp;||&nbsp;
 
19
<a href="color.html">Color</a>&nbsp;||&nbsp;
 
20
<a href="cursors.html">Cursors</a>&nbsp;||&nbsp;
 
21
<a href="display.html">Display</a>&nbsp;||&nbsp;
 
22
<a href="draw.html">Draw</a>&nbsp;||&nbsp;
 
23
<a href="event.html">Event</a>&nbsp;||&nbsp;
 
24
<a href="examples.html">Examples</a>&nbsp;||&nbsp;
 
25
<a href="font.html">Font</a>&nbsp;||&nbsp;
 
26
<a href="gfxdraw.html">Gfxdraw</a>&nbsp;||&nbsp;
 
27
<a href="image.html">Image</a>&nbsp;||&nbsp;
 
28
<a href="joystick.html">Joystick</a>&nbsp;||&nbsp;
 
29
<a href="key.html">Key</a>&nbsp;||&nbsp;
 
30
<a href="locals.html">Locals</a>&nbsp;||&nbsp;
 
31
<a href="mask.html">Mask</a>&nbsp;||&nbsp;
 
32
<a href="midi.html">Midi</a>&nbsp;||&nbsp;
 
33
<a href="mixer.html">Mixer</a>&nbsp;||&nbsp;
 
34
<a href="mouse.html">Mouse</a>&nbsp;||&nbsp;
 
35
<a href="movie.html">Movie</a>&nbsp;||&nbsp;
 
36
<a href="music.html">Music</a>&nbsp;||&nbsp;
 
37
<a href="overlay.html">Overlay</a>&nbsp;||&nbsp;
 
38
<a href="pixelarray.html">Pixelarray</a>&nbsp;||&nbsp;
 
39
<a href="pygame.html">Pygame</a>&nbsp;||&nbsp;
 
40
<a href="rect.html">Rect</a>&nbsp;||&nbsp;
 
41
<a href="scrap.html">Scrap</a>&nbsp;||&nbsp;
 
42
<a href="sndarray.html">Sndarray</a>&nbsp;||&nbsp;
 
43
<a href="sprite.html">Sprite</a>&nbsp;||&nbsp;
 
44
<a href="surface.html">Surface</a>&nbsp;||&nbsp;
 
45
<a href="surfarray.html">Surfarray</a>&nbsp;||&nbsp;
 
46
<a href="tests.html">Tests</a>&nbsp;||&nbsp;
 
47
<a href="time.html">Time</a>&nbsp;||&nbsp;
 
48
<a href="transform.html">Transform</a>
 
49
</td></tr></table>
 
50
<br>
 
51
 
 
52
 
 
53
<a name="pygame.sprite">
 
54
<big><b>pygame.sprite</big></b><br><ul>
 
55
  <i>pygame module with basic game object classes</i><br>
 
56
<ul><small><table>
 
57
  <tr><td><a href="sprite.html#pygame.sprite.Sprite">pygame.sprite.Sprite</a> - <font size=-1>simple base class for visible game objects</font></td><td>simple base class for visible game objects</td></tr>
 
58
  <tr><td><a href="sprite.html#pygame.sprite.DirtySprite">pygame.sprite.DirtySprite</a> - <font size=-1>a more featureful subclass of Sprite with more attributes</font></td><td>a more featureful subclass of Sprite with more attributes</td></tr>
 
59
  <tr><td><a href="sprite.html#pygame.sprite.Group">pygame.sprite.Group</a> - <font size=-1>container class for many Sprites</font></td><td>container class for many Sprites</td></tr>
 
60
  <tr><td><a href="sprite.html#pygame.sprite.RenderUpdates">pygame.sprite.RenderUpdates</a> - <font size=-1>Group class that tracks dirty updates</font></td><td>Group class that tracks dirty updates</td></tr>
 
61
  <tr><td><a href="sprite.html#pygame.sprite.OrderedUpdates">pygame.sprite.OrderedUpdates</a> - <font size=-1>RenderUpdates class that draws Sprites in order of addition</font></td><td>RenderUpdates class that draws Sprites in order of addition</td></tr>
 
62
  <tr><td><a href="sprite.html#pygame.sprite.LayeredUpdates">pygame.sprite.LayeredUpdates</a> - <font size=-1>LayeredUpdates Group handles layers, that draws like OrderedUpdates.</font></td><td>LayeredUpdates Group handles layers, that draws like OrderedUpdates.</td></tr>
 
63
  <tr><td><a href="sprite.html#pygame.sprite.LayeredDirty">pygame.sprite.LayeredDirty</a> - <font size=-1>LayeredDirty Group is for DirtySprites.  Subclasses LayeredUpdates.</font></td><td>LayeredDirty Group is for DirtySprites.  Subclasses LayeredUpdates.</td></tr>
 
64
  <tr><td><a href="sprite.html#pygame.sprite.GroupSingle">pygame.sprite.GroupSingle</a> - <font size=-1>Group container that holds a single Sprite</font></td><td>Group container that holds a single Sprite</td></tr>
 
65
  <tr><td><a href="sprite.html#pygame.sprite.spritecollide">pygame.sprite.spritecollide</a> - <font size=-1>find Sprites in a Group that intersect another Sprite</font></td><td>find Sprites in a Group that intersect another Sprite</td></tr>
 
66
  <tr><td><a href="sprite.html#pygame.sprite.collide_rect">pygame.sprite.collide_rect</a> - <font size=-1>collision detection between two sprites, using rects.</font></td><td>collision detection between two sprites, using rects.</td></tr>
 
67
  <tr><td><a href="sprite.html#pygame.sprite.collide_rect_ratio">pygame.sprite.collide_rect_ratio</a> - <font size=-1>collision detection between two sprites, using rects scaled to a ratio.</font></td><td>collision detection between two sprites, using rects scaled to a ratio.</td></tr>
 
68
  <tr><td><a href="sprite.html#pygame.sprite.collide_circle">pygame.sprite.collide_circle</a> - <font size=-1>collision detection between two sprites, using circles.</font></td><td>collision detection between two sprites, using circles.</td></tr>
 
69
  <tr><td><a href="sprite.html#pygame.sprite.collide_circle_ratio">pygame.sprite.collide_circle_ratio</a> - <font size=-1>collision detection between two sprites, using circles scaled to a ratio.</font></td><td>collision detection between two sprites, using circles scaled to a ratio.</td></tr>
 
70
  <tr><td><a href="sprite.html#pygame.sprite.collide_mask">pygame.sprite.collide_mask</a> - <font size=-1>collision detection between two sprites, using masks.</font></td><td>collision detection between two sprites, using masks.</td></tr>
 
71
  <tr><td><a href="sprite.html#pygame.sprite.groupcollide">pygame.sprite.groupcollide</a> - <font size=-1>find all Sprites that collide between two Groups</font></td><td>find all Sprites that collide between two Groups</td></tr>
 
72
  <tr><td><a href="sprite.html#pygame.sprite.spritecollideany">pygame.sprite.spritecollideany</a> - <font size=-1>simple test if a Sprite intersects anything in a Group</font></td><td>simple test if a Sprite intersects anything in a Group</td></tr>
 
73
  <tr><td>None</td><td></td></tr>
 
74
</table></small></ul>
 
75
<p>This module contains several simple classes to be used within games. There is the main Sprite class and several Group classes that contain Sprites. The use of these classes is entirely optional when using Pygame. The classes are fairly lightweight and only provide a starting place for the code that is common to most games. </p>
 
76
<p>The Sprite class is intended to be used as a base class for the different types of objects in the game. There is also a base Group class that simply stores sprites. <tt>A</tt> game could create new types of Group classes that operate on specially customized Sprite instances they contain. </p>
 
77
<p>The basic Sprite class can draw the Sprites it contains to a Surface. The <tt><a href="sprite.html#Group.draw">Group.draw</a> - <font size=-1>blit the Sprite images</font></tt> method requires that each Sprite have a <tt>Surface.image</tt> attribute and a <tt>Surface.rect</tt>. The <tt><a href="sprite.html#Group.clear">Group.clear</a> - <font size=-1>draw a background over the Sprites</font></tt> method requires these same attributes, and can be used to erase all the Sprites with background. There are also more advanced Groups: <tt><a href="sprite.html#pygame.sprite.RenderUpdates">pygame.sprite.RenderUpdates</a> - <font size=-1>Group class that tracks dirty updates</font></tt> and <tt><a href="sprite.html#pygame.sprite.OrderedUpdates">pygame.sprite.OrderedUpdates</a> - <font size=-1>RenderUpdates class that draws Sprites in order of addition</font></tt>. </p>
 
78
<p>Lastly, this module contains several collision functions. These help find sprites inside multiple groups that have intersecting bounding rectangles. To find the collisions, the Sprites are required to have a <tt>Surface.rect</tt> attribute assigned. </p>
 
79
<p>The groups are designed for high efficiency in removing and adding Sprites to them. They also allow cheap testing to see if a Sprite already exists in a Group. <tt>A</tt> given Sprite can exist in any number of groups. <tt>A</tt> game could use some groups to control object rendering, and a completely separate set of groups to control interaction or player movement. Instead of adding type attributes or bools to a derived Sprite class, consider keeping the Sprites inside organized Groups. This will allow for easier lookup later in the game. </p>
 
80
<p>Sprites and Groups manage their relationships with the add() and remove() methods. These methods can accept a single or multiple targets for membership. The default initializers for these classes also takes a single or list of targets for initial membership. It is safe to repeatedly add and remove the same Sprite from a Group. </p>
 
81
<p>While it is possible to design sprite and group classes that don't derive from the Sprite and AbstractGroup classes below, it is strongly recommended that you extend those when you add a Sprite or Group class. </p>
 
82
<p>Sprites are not thread safe. So lock them yourself if using threads. </p>
 
83
<!--COMMENTS:pygame.sprite--> &nbsp;<br> 
 
84
 
 
85
 
 
86
<a name="pygame.sprite.Sprite">
 
87
<big><b>pygame.sprite.Sprite</big></b><br><ul>
 
88
  <i>simple base class for visible game objects</i><br>
 
89
  <tt>pygame.sprite.Sprite(*groups): return Sprite</tt><br>
 
90
<ul><small><table>
 
91
  <tr><td><a href="sprite.html#Sprite.update">Sprite.update</a> - <font size=-1>method to control sprite behavior</font></td><td>method to control sprite behavior</td></tr>
 
92
  <tr><td><a href="sprite.html#Sprite.add">Sprite.add</a> - <font size=-1>add the sprite to groups</font></td><td>add the sprite to groups</td></tr>
 
93
  <tr><td><a href="sprite.html#Sprite.remove">Sprite.remove</a> - <font size=-1>remove the sprite from groups</font></td><td>remove the sprite from groups</td></tr>
 
94
  <tr><td><a href="sprite.html#Sprite.kill">Sprite.kill</a> - <font size=-1>remove the Sprite from all Groups</font></td><td>remove the Sprite from all Groups</td></tr>
 
95
  <tr><td><a href="sprite.html#Sprite.alive">Sprite.alive</a> - <font size=-1>does the sprite belong to any groups</font></td><td>does the sprite belong to any groups</td></tr>
 
96
  <tr><td><a href="sprite.html#Sprite.groups">Sprite.groups</a> - <font size=-1>list of Groups that contain this Sprite</font></td><td>list of Groups that contain this Sprite</td></tr>
 
97
</table></small></ul>
 
98
<p>The base class for visible game objects. Derived classes will want to override the <tt><a href="sprite.html#Sprite.update">Sprite.update</a> - <font size=-1>method to control sprite behavior</font></tt> and assign a <tt>Sprite.image</tt> and <tt>Sprite.rect</tt> attributes. The initializer can accept any number of Group instances to be added to. </p>
 
99
<p>When subclassing the Sprite, be sure to call the base initializer before adding the Sprite to Groups. </p>
 
100
<!--COMMENTS:pygame.sprite.Sprite--> &nbsp;<br> 
 
101
 
 
102
 
 
103
<a name="Sprite.update">
 
104
<big><b>Sprite.update</big></b><br><ul>
 
105
  <i>method to control sprite behavior</i><br>
 
106
  <tt>Sprite.update(*args):</tt><br>
 
107
<p>The default implementation of this method does nothing; it's just a convenient "hook" that you can override. This method is called by <tt><a href="sprite.html#Group.update">Group.update</a> - <font size=-1>call the update method on contained Sprites</font></tt> with whatever arguments you give it. </p>
 
108
<p>There is no need to use this method if not using the convenience method by the same name in the Group class. </p>
 
109
<!--COMMENTS:Sprite.update--> &nbsp;<br> 
 
110
<br></ul>
 
111
 
 
112
 
 
113
<a name="Sprite.add">
 
114
<big><b>Sprite.add</big></b><br><ul>
 
115
  <i>add the sprite to groups</i><br>
 
116
  <tt>Sprite.add(*groups): return None</tt><br>
 
117
<p>Any number of Group instances can be passed as arguments. The Sprite will be added to the Groups it is not already a member of. </p>
 
118
<!--COMMENTS:Sprite.add--> &nbsp;<br> 
 
119
<br></ul>
 
120
 
 
121
 
 
122
<a name="Sprite.remove">
 
123
<big><b>Sprite.remove</big></b><br><ul>
 
124
  <i>remove the sprite from groups</i><br>
 
125
  <tt>Sprite.remove(*groups): return None</tt><br>
 
126
<p>Any number of Group instances can be passed as arguments. The Sprite will be removed from the Groups it is currently a member of. </p>
 
127
<!--COMMENTS:Sprite.remove--> &nbsp;<br> 
 
128
<br></ul>
 
129
 
 
130
 
 
131
<a name="Sprite.kill">
 
132
<big><b>Sprite.kill</big></b><br><ul>
 
133
  <i>remove the Sprite from all Groups</i><br>
 
134
  <tt>Sprite.kill(): return None</tt><br>
 
135
<p>The Sprite is removed from all the Groups that contain it. This won't change anything about the state of the Sprite. It is possible to continue to use the Sprite after this method has been called, including adding it to Groups. </p>
 
136
<!--COMMENTS:Sprite.kill--> &nbsp;<br> 
 
137
<br></ul>
 
138
 
 
139
 
 
140
<a name="Sprite.alive">
 
141
<big><b>Sprite.alive</big></b><br><ul>
 
142
  <i>does the sprite belong to any groups</i><br>
 
143
  <tt>Sprite.alive(): return bool</tt><br>
 
144
<p>Returns True when the Sprite belongs to one or more Groups. </p>
 
145
<!--COMMENTS:Sprite.alive--> &nbsp;<br> 
 
146
<br></ul>
 
147
 
 
148
 
 
149
<a name="Sprite.groups">
 
150
<big><b>Sprite.groups</big></b><br><ul>
 
151
  <i>list of Groups that contain this Sprite</i><br>
 
152
  <tt>Sprite.groups(): return group_list</tt><br>
 
153
<p>Return a list of all the Groups that contain this Sprite. </p>
 
154
<!--COMMENTS:Sprite.groups--> &nbsp;<br> 
 
155
<br></ul>
 
156
<br></ul>
 
157
 
 
158
 
 
159
<a name="pygame.sprite.DirtySprite">
 
160
<big><b>pygame.sprite.DirtySprite</big></b><br><ul>
 
161
  <i>a more featureful subclass of Sprite with more attributes</i><br>
 
162
  <tt>pygame.sprite.DirtySprite(*groups): return DirtySprite</tt><br>
 
163
<ul><small><table>
 
164
  <tr><td>None</td><td></td></tr>
 
165
</table></small></ul>
 
166
<p>Extra DirtySprite attributes with their default values: </p>
 
167
<p>dirty = 1 </p>
 
168
<pre>    if set to 1, it is repainted and then set to 0 again
 
169
    if set to 2 then it is always dirty ( repainted each frame,
 
170
    flag is not reset)
 
171
    0 means that it is not dirty and therefor not repainted again
 
172
</pre><p>blendmode = 0 </p>
 
173
<pre>    its the special_flags argument of blit, blendmodes
 
174
</pre><p>source_rect = None </p>
 
175
<pre>    source rect to use, remember that it is relative to
 
176
    topleft (0,0) of self.image
 
177
</pre><p>visible = 1 </p>
 
178
<pre>    normally 1, if set to 0 it will not be repainted
 
179
    (you must set it dirty too to be erased from screen)
 
180
</pre><p>layer = 0 </p>
 
181
<pre>    (READONLY value, it is read when adding it to the
 
182
    LayeredRenderGroup, for details see doc of LayeredRenderGroup)
 
183
</pre>
 
184
<!--COMMENTS:pygame.sprite.DirtySprite--> &nbsp;<br> 
 
185
 
 
186
 
 
187
<a name="">
 
188
<big><b></big></b><br><ul>
 
189
 &nbsp;<br> 
 
190
<!--COMMENTS:--> &nbsp;<br> 
 
191
<br></ul>
 
192
<br></ul>
 
193
 
 
194
 
 
195
<a name="pygame.sprite.Group">
 
196
<big><b>pygame.sprite.Group</big></b><br><ul>
 
197
  <i>container class for many Sprites</i><br>
 
198
  <tt>pygame.sprite.Group(*sprites): return Group</tt><br>
 
199
<ul><small><table>
 
200
  <tr><td><a href="sprite.html#Group.sprites">Group.sprites</a> - <font size=-1>list of the Sprites this Group contains</font></td><td>list of the Sprites this Group contains</td></tr>
 
201
  <tr><td><a href="sprite.html#Group.copy">Group.copy</a> - <font size=-1>duplicate the Group</font></td><td>duplicate the Group</td></tr>
 
202
  <tr><td><a href="sprite.html#Group.add">Group.add</a> - <font size=-1>add Sprites to this Group</font></td><td>add Sprites to this Group</td></tr>
 
203
  <tr><td><a href="sprite.html#Group.remove">Group.remove</a> - <font size=-1>remove Sprites from the Group</font></td><td>remove Sprites from the Group</td></tr>
 
204
  <tr><td><a href="sprite.html#Group.has">Group.has</a> - <font size=-1>test if a Group contains Sprites</font></td><td>test if a Group contains Sprites</td></tr>
 
205
  <tr><td><a href="sprite.html#Group.update">Group.update</a> - <font size=-1>call the update method on contained Sprites</font></td><td>call the update method on contained Sprites</td></tr>
 
206
  <tr><td><a href="sprite.html#Group.draw">Group.draw</a> - <font size=-1>blit the Sprite images</font></td><td>blit the Sprite images</td></tr>
 
207
  <tr><td><a href="sprite.html#Group.clear">Group.clear</a> - <font size=-1>draw a background over the Sprites</font></td><td>draw a background over the Sprites</td></tr>
 
208
  <tr><td><a href="sprite.html#Group.empty">Group.empty</a> - <font size=-1>remove all Sprites</font></td><td>remove all Sprites</td></tr>
 
209
</table></small></ul>
 
210
<p><tt>A</tt> simple container for Sprite objects. This class can be inherited to create containers with more specific behaviors. The constructor takes any number of Sprite arguments to add to the Group. The group supports the following standard Python operations: </p>
 
211
<pre>    in      test if a Sprite is contained
 
212
    len     the number of Sprites contained
 
213
    bool test if any Sprites are contained
 
214
    iter    iterate through all the Sprites
 
215
</pre><p>The Sprites in the Group are not ordered, so drawing and iterating the Sprites is in no particular order. </p>
 
216
<!--COMMENTS:pygame.sprite.Group--> &nbsp;<br> 
 
217
 
 
218
 
 
219
<a name="Group.sprites">
 
220
<big><b>Group.sprites</big></b><br><ul>
 
221
  <i>list of the Sprites this Group contains</i><br>
 
222
  <tt>Group.sprites(): return sprite_list</tt><br>
 
223
<p>Return a list of all the Sprites this group contains. You can also get an iterator from the group, but you cannot iterator over a Group while modifying it. </p>
 
224
<!--COMMENTS:Group.sprites--> &nbsp;<br> 
 
225
<br></ul>
 
226
 
 
227
 
 
228
<a name="Group.copy">
 
229
<big><b>Group.copy</big></b><br><ul>
 
230
  <i>duplicate the Group</i><br>
 
231
  <tt>Group.copy(): return Group</tt><br>
 
232
<p>Creates a new Group with all the same Sprites as the original. If you have subclassed Group, the new object will have the same (sub-)class as the original. This only works if the derived class's constructor takes the same arguments as the Group class's. </p>
 
233
<!--COMMENTS:Group.copy--> &nbsp;<br> 
 
234
<br></ul>
 
235
 
 
236
 
 
237
<a name="Group.add">
 
238
<big><b>Group.add</big></b><br><ul>
 
239
  <i>add Sprites to this Group</i><br>
 
240
  <tt>Group.add(*sprites): return None</tt><br>
 
241
<p>Add any number of Sprites to this Group. This will only add Sprites that are not already members of the Group. </p>
 
242
<p>Each sprite argument can also be a iterator containing Sprites. </p>
 
243
<!--COMMENTS:Group.add--> &nbsp;<br> 
 
244
<br></ul>
 
245
 
 
246
 
 
247
<a name="Group.remove">
 
248
<big><b>Group.remove</big></b><br><ul>
 
249
  <i>remove Sprites from the Group</i><br>
 
250
  <tt>Group.remove(*sprites): return None</tt><br>
 
251
<p>Remove any number of Sprites from the Group. This will only remove Sprites that are already members of the Group. </p>
 
252
<p>Each sprite argument can also be a iterator containing Sprites. </p>
 
253
<!--COMMENTS:Group.remove--> &nbsp;<br> 
 
254
<br></ul>
 
255
 
 
256
 
 
257
<a name="Group.has">
 
258
<big><b>Group.has</big></b><br><ul>
 
259
  <i>test if a Group contains Sprites</i><br>
 
260
  <tt>Group.has(*sprites): return None</tt><br>
 
261
<p>Return True if the Group contains all of the given sprites. This is similar to using the "in" operator on the Group ("if sprite in group: <tt>...")</tt>, which tests if a single Sprite belongs to a Group. </p>
 
262
<p>Each sprite argument can also be a iterator containing Sprites. </p>
 
263
<!--COMMENTS:Group.has--> &nbsp;<br> 
 
264
<br></ul>
 
265
 
 
266
 
 
267
<a name="Group.update">
 
268
<big><b>Group.update</big></b><br><ul>
 
269
  <i>call the update method on contained Sprites</i><br>
 
270
  <tt>Group.update(*args): return None</tt><br>
 
271
<p>Calls the update() method on all Sprites in the Group. The base Sprite class has an update method that takes any number of arguments and does nothing. The arguments passed to <tt><a href="sprite.html#Group.update">Group.update</a> - <font size=-1>call the update method on contained Sprites</font></tt> will be passed to each Sprite. </p>
 
272
<p>There is no way to get the return value from the <tt><a href="sprite.html#Sprite.update">Sprite.update</a> - <font size=-1>method to control sprite behavior</font></tt> methods. </p>
 
273
<!--COMMENTS:Group.update--> &nbsp;<br> 
 
274
<br></ul>
 
275
 
 
276
 
 
277
<a name="Group.draw">
 
278
<big><b>Group.draw</big></b><br><ul>
 
279
  <i>blit the Sprite images</i><br>
 
280
  <tt>Group.draw(Surface): return None</tt><br>
 
281
<p>Draws the contained Sprites to the Surface argument. This uses the <tt>Sprite.image</tt> attribute for the source surface, and <tt>Sprite.rect</tt> for the position. </p>
 
282
<p>The Group does not keep sprites in any order, so the draw order is arbitrary. </p>
 
283
<!--COMMENTS:Group.draw--> &nbsp;<br> 
 
284
<br></ul>
 
285
 
 
286
 
 
287
<a name="Group.clear">
 
288
<big><b>Group.clear</big></b><br><ul>
 
289
  <i>draw a background over the Sprites</i><br>
 
290
  <tt>Group.clear(Surface_dest, background): return None</tt><br>
 
291
<p>Erases the Sprites used in the last <tt><a href="sprite.html#Group.draw">Group.draw</a> - <font size=-1>blit the Sprite images</font></tt> call. The destination Surface is cleared by filling the drawn Sprite positions with the background. </p>
 
292
<p>The background is usually a Surface image the same dimensions as the destination Surface. However, it can also be a callback function that takes two arguments; the destination Surface and an area to clear. The background callback function will be called several times each clear. </p>
 
293
<p>Here is an example callback that will clear the Sprites with solid red: </p>
 
294
<pre>    def clear_callback(surf, rect):
 
295
        color = 255, 0, 0
 
296
        surf.fill(color, rect)
 
297
</pre>
 
298
<!--COMMENTS:Group.clear--> &nbsp;<br> 
 
299
<br></ul>
 
300
 
 
301
 
 
302
<a name="Group.empty">
 
303
<big><b>Group.empty</big></b><br><ul>
 
304
  <i>remove all Sprites</i><br>
 
305
  <tt>Group.empty(): return None</tt><br>
 
306
<p>Removes all Sprites from this Group. </p>
 
307
<!--COMMENTS:Group.empty--> &nbsp;<br> 
 
308
<br></ul>
 
309
<br></ul>
 
310
 
 
311
 
 
312
<a name="pygame.sprite.RenderUpdates">
 
313
<big><b>pygame.sprite.RenderUpdates</big></b><br><ul>
 
314
  <i>Group class that tracks dirty updates</i><br>
 
315
  <tt>pygame.sprite.RenderUpdates(*sprites): return RenderUpdates</tt><br>
 
316
<ul><small><table>
 
317
  <tr><td><a href="sprite.html#RenderUpdates.draw">RenderUpdates.draw</a> - <font size=-1>blit the Sprite images and track changed areas</font></td><td>blit the Sprite images and track changed areas</td></tr>
 
318
</table></small></ul>
 
319
<p>This class is derived from <tt><a href="sprite.html#pygame.sprite.Group">pygame.sprite.Group</a> - <font size=-1>container class for many Sprites</font></tt>. It has an extended draw() method that tracks the changed areas of the screen. </p>
 
320
<!--COMMENTS:pygame.sprite.RenderUpdates--> &nbsp;<br> 
 
321
 
 
322
 
 
323
<a name="RenderUpdates.draw">
 
324
<big><b>RenderUpdates.draw</big></b><br><ul>
 
325
  <i>blit the Sprite images and track changed areas</i><br>
 
326
  <tt>RenderUpdates.draw(surface): return Rect_list</tt><br>
 
327
<p>Draws all the Sprites to the surface, the same as <tt><a href="sprite.html#Group.draw">Group.draw</a> - <font size=-1>blit the Sprite images</font></tt>. This method also returns a list of Rectangular areas on the screen that have been changed. The returned changes include areas of the screen that have been affected by previous <tt><a href="sprite.html#Group.clear">Group.clear</a> - <font size=-1>draw a background over the Sprites</font></tt> calls. </p>
 
328
<p>The returned Rect list should be passed to <tt><a href="display.html#pygame.display.update">pygame.display.update</a> - <font size=-1>update portions of the screen for software displays</font></tt>. This will help performance on software driven display modes. This type of updating is usually only helpful on destinations with non-animating backgrounds. </p>
 
329
<!--COMMENTS:RenderUpdates.draw--> &nbsp;<br> 
 
330
<br></ul>
 
331
<br></ul>
 
332
 
 
333
 
 
334
<a name="pygame.sprite.OrderedUpdates">
 
335
<big><b>pygame.sprite.OrderedUpdates</big></b><br><ul>
 
336
  <i>RenderUpdates class that draws Sprites in order of addition</i><br>
 
337
  <tt>pygame.sprite.OrderedUpdates(*spites): return OrderedUpdates</tt><br>
 
338
<p>This class derives from <tt><a href="sprite.html#pygame.sprite.RenderUpdates">pygame.sprite.RenderUpdates</a> - <font size=-1>Group class that tracks dirty updates</font></tt>. It maintains the order in which the Sprites were added to the Group for rendering. This makes adding and removing Sprites from the Group a little slower than regular Groups. </p>
 
339
<!--COMMENTS:pygame.sprite.OrderedUpdates--> &nbsp;<br> 
 
340
<br></ul>
 
341
 
 
342
 
 
343
<a name="pygame.sprite.LayeredUpdates">
 
344
<big><b>pygame.sprite.LayeredUpdates</big></b><br><ul>
 
345
  <i>LayeredUpdates Group handles layers, that draws like OrderedUpdates.</i><br>
 
346
  <tt>pygame.sprite.LayeredUpdates(*spites, **kwargs): return LayeredUpdates</tt><br>
 
347
<ul><small><table>
 
348
  <tr><td><a href="sprite.html#LayeredUpdates.add">LayeredUpdates.add</a> - <font size=-1>add a sprite or sequence of sprites to a group</font></td><td>add a sprite or sequence of sprites to a group</td></tr>
 
349
  <tr><td><a href="sprite.html#LayeredUpdates.sprites">LayeredUpdates.sprites</a> - <font size=-1>returns a ordered list of sprites (first back, last top).</font></td><td>returns a ordered list of sprites (first back, last top).</td></tr>
 
350
  <tr><td><a href="sprite.html#LayeredUpdates.draw">LayeredUpdates.draw</a> - <font size=-1>draw all sprites in the right order onto the passed surface.</font></td><td>draw all sprites in the right order onto the passed surface.</td></tr>
 
351
  <tr><td><a href="sprite.html#LayeredUpdates.get_sprites_at">LayeredUpdates.get_sprites_at</a> - <font size=-1>returns a list with all sprites at that position.</font></td><td>returns a list with all sprites at that position.</td></tr>
 
352
  <tr><td><a href="sprite.html#LayeredUpdates.get_sprite">LayeredUpdates.get_sprite</a> - <font size=-1>returns the sprite at the index idx from the groups sprites</font></td><td>returns the sprite at the index idx from the groups sprites</td></tr>
 
353
  <tr><td><a href="sprite.html#LayeredUpdates.remove_sprites_of_layer">LayeredUpdates.remove_sprites_of_layer</a> - <font size=-1>removes all sprites from a layer and returns them as a list.</font></td><td>removes all sprites from a layer and returns them as a list.</td></tr>
 
354
  <tr><td><a href="sprite.html#LayeredUpdates.layers">LayeredUpdates.layers</a> - <font size=-1>returns a list of layers defined (unique), sorted from botton up.</font></td><td>returns a list of layers defined (unique), sorted from botton up.</td></tr>
 
355
  <tr><td><a href="sprite.html#LayeredUpdates.change_layer">LayeredUpdates.change_layer</a> - <font size=-1>changes the layer of the sprite</font></td><td>changes the layer of the sprite</td></tr>
 
356
  <tr><td><a href="sprite.html#LayeredUpdates.get_layer_of_sprite">LayeredUpdates.get_layer_of_sprite</a> - <font size=-1>returns the layer that sprite is currently in.</font></td><td>returns the layer that sprite is currently in.</td></tr>
 
357
  <tr><td><a href="sprite.html#LayeredUpdates.get_top_layer">LayeredUpdates.get_top_layer</a> - <font size=-1>returns the top layer</font></td><td>returns the top layer</td></tr>
 
358
  <tr><td><a href="sprite.html#LayeredUpdates.get_bottom_layer">LayeredUpdates.get_bottom_layer</a> - <font size=-1>returns the bottom layer</font></td><td>returns the bottom layer</td></tr>
 
359
  <tr><td><a href="sprite.html#LayeredUpdates.move_to_front">LayeredUpdates.move_to_front</a> - <font size=-1>brings the sprite to front layer</font></td><td>brings the sprite to front layer</td></tr>
 
360
  <tr><td><a href="sprite.html#LayeredUpdates.move_to_back">LayeredUpdates.move_to_back</a> - <font size=-1>moves the sprite to the bottom layer</font></td><td>moves the sprite to the bottom layer</td></tr>
 
361
  <tr><td><a href="sprite.html#LayeredUpdates.get_top_sprite">LayeredUpdates.get_top_sprite</a> - <font size=-1>returns the topmost sprite</font></td><td>returns the topmost sprite</td></tr>
 
362
  <tr><td><a href="sprite.html#LayeredUpdates.get_sprites_from_layer">LayeredUpdates.get_sprites_from_layer</a> - <font size=-1>returns all sprites from a layer, ordered by how they where added</font></td><td>returns all sprites from a layer, ordered by how they where added</td></tr>
 
363
  <tr><td><a href="sprite.html#LayeredUpdates.switch_layer">LayeredUpdates.switch_layer</a> - <font size=-1>switches the sprites from layer1 to layer2</font></td><td>switches the sprites from layer1 to layer2</td></tr>
 
364
</table></small></ul>
 
365
<p>This group is fully compatible with <tt>pygame.sprite.Sprite</tt>. </p>
 
366
<p>You can set the default layer through kwargs using 'default_layer' and an integer for the layer. The default layer is 0. </p>
 
367
<p>If the sprite you add has an attribute layer then that layer will be used. If the **kwarg contains 'layer' then the sprites passed will be added to that layer (overriding the <tt>sprite.layer</tt> attribute). If neither sprite has attribute layer nor **kwarg then the default layer is used to add the sprites. </p>
 
368
<p>New in pygame <tt>1.8.0</tt> </p>
 
369
<!--COMMENTS:pygame.sprite.LayeredUpdates--> &nbsp;<br> 
 
370
 
 
371
 
 
372
<a name="LayeredUpdates.add">
 
373
<big><b>LayeredUpdates.add</big></b><br><ul>
 
374
  <i>add a sprite or sequence of sprites to a group</i><br>
 
375
  <tt>LayeredUpdates.add(*sprites, **kwargs): return None</tt><br>
 
376
<p>If the sprite(s) have an attribute layer then that is used for the layer. If **kwargs contains 'layer' then the sprite(s) will be added to that argument (overriding the sprite layer attribute). If neither is passed then the sprite(s) will be added to the default layer. </p>
 
377
<!--COMMENTS:LayeredUpdates.add--> &nbsp;<br> 
 
378
<br></ul>
 
379
 
 
380
 
 
381
<a name="LayeredUpdates.sprites">
 
382
<big><b>LayeredUpdates.sprites</big></b><br><ul>
 
383
  <i>returns a ordered list of sprites (first back, last top).</i><br>
 
384
  <tt>LayeredUpdates.sprites(): return sprites</tt><br>
 
385
 &nbsp;<br> 
 
386
<!--COMMENTS:LayeredUpdates.sprites--> &nbsp;<br> 
 
387
<br></ul>
 
388
 
 
389
 
 
390
<a name="LayeredUpdates.draw">
 
391
<big><b>LayeredUpdates.draw</big></b><br><ul>
 
392
  <i>draw all sprites in the right order onto the passed surface.</i><br>
 
393
  <tt>LayeredUpdates.draw(surface): return Rect_list</tt><br>
 
394
 &nbsp;<br> 
 
395
<!--COMMENTS:LayeredUpdates.draw--> &nbsp;<br> 
 
396
<br></ul>
 
397
 
 
398
 
 
399
<a name="LayeredUpdates.get_sprites_at">
 
400
<big><b>LayeredUpdates.get_sprites_at</big></b><br><ul>
 
401
  <i>returns a list with all sprites at that position.</i><br>
 
402
  <tt>LayeredUpdates.get_sprites_at(pos): return colliding_sprites</tt><br>
 
403
<p>Bottom sprites first, top last. </p>
 
404
<!--COMMENTS:LayeredUpdates.get_sprites_at--> &nbsp;<br> 
 
405
<br></ul>
 
406
 
 
407
 
 
408
<a name="LayeredUpdates.get_sprite">
 
409
<big><b>LayeredUpdates.get_sprite</big></b><br><ul>
 
410
  <i>returns the sprite at the index idx from the groups sprites</i><br>
 
411
  <tt>LayeredUpdates.get_sprite(idx): return sprite</tt><br>
 
412
<p>Raises IndexOutOfBounds if the idx is not within range. </p>
 
413
<!--COMMENTS:LayeredUpdates.get_sprite--> &nbsp;<br> 
 
414
<br></ul>
 
415
 
 
416
 
 
417
<a name="LayeredUpdates.remove_sprites_of_layer">
 
418
<big><b>LayeredUpdates.remove_sprites_of_layer</big></b><br><ul>
 
419
  <i>removes all sprites from a layer and returns them as a list.</i><br>
 
420
  <tt>LayeredUpdates.remove_sprites_of_layer(layer_nr): return sprites</tt><br>
 
421
 &nbsp;<br> 
 
422
<!--COMMENTS:LayeredUpdates.remove_sprites_of_layer--> &nbsp;<br> 
 
423
<br></ul>
 
424
 
 
425
 
 
426
<a name="LayeredUpdates.layers">
 
427
<big><b>LayeredUpdates.layers</big></b><br><ul>
 
428
  <i>returns a list of layers defined (unique), sorted from botton up.</i><br>
 
429
  <tt>LayeredUpdates.layers(): return layers</tt><br>
 
430
 &nbsp;<br> 
 
431
<!--COMMENTS:LayeredUpdates.layers--> &nbsp;<br> 
 
432
<br></ul>
 
433
 
 
434
 
 
435
<a name="LayeredUpdates.change_layer">
 
436
<big><b>LayeredUpdates.change_layer</big></b><br><ul>
 
437
  <i>changes the layer of the sprite</i><br>
 
438
  <tt>LayeredUpdates.change_layer(sprite, new_layer): return None</tt><br>
 
439
<p>sprite must have been added to the renderer. It is not checked. </p>
 
440
<!--COMMENTS:LayeredUpdates.change_layer--> &nbsp;<br> 
 
441
<br></ul>
 
442
 
 
443
 
 
444
<a name="LayeredUpdates.get_layer_of_sprite">
 
445
<big><b>LayeredUpdates.get_layer_of_sprite</big></b><br><ul>
 
446
  <i>returns the layer that sprite is currently in.</i><br>
 
447
  <tt>LayeredUpdates.get_layer_of_sprite(sprite): return layer</tt><br>
 
448
<p>If the sprite is not found then it will return the default layer. </p>
 
449
<!--COMMENTS:LayeredUpdates.get_layer_of_sprite--> &nbsp;<br> 
 
450
<br></ul>
 
451
 
 
452
 
 
453
<a name="LayeredUpdates.get_top_layer">
 
454
<big><b>LayeredUpdates.get_top_layer</big></b><br><ul>
 
455
  <i>returns the top layer</i><br>
 
456
  <tt>LayeredUpdates.get_top_layer(): return layer</tt><br>
 
457
 &nbsp;<br> 
 
458
<!--COMMENTS:LayeredUpdates.get_top_layer--> &nbsp;<br> 
 
459
<br></ul>
 
460
 
 
461
 
 
462
<a name="LayeredUpdates.get_bottom_layer">
 
463
<big><b>LayeredUpdates.get_bottom_layer</big></b><br><ul>
 
464
  <i>returns the bottom layer</i><br>
 
465
  <tt>LayeredUpdates.get_bottom_layer(): return layer</tt><br>
 
466
 &nbsp;<br> 
 
467
<!--COMMENTS:LayeredUpdates.get_bottom_layer--> &nbsp;<br> 
 
468
<br></ul>
 
469
 
 
470
 
 
471
<a name="LayeredUpdates.move_to_front">
 
472
<big><b>LayeredUpdates.move_to_front</big></b><br><ul>
 
473
  <i>brings the sprite to front layer</i><br>
 
474
  <tt>LayeredUpdates.move_to_front(sprite): return None</tt><br>
 
475
<p>Brings the sprite to front, changing sprite layer to topmost layer (added at the end of that layer). </p>
 
476
<!--COMMENTS:LayeredUpdates.move_to_front--> &nbsp;<br> 
 
477
<br></ul>
 
478
 
 
479
 
 
480
<a name="LayeredUpdates.move_to_back">
 
481
<big><b>LayeredUpdates.move_to_back</big></b><br><ul>
 
482
  <i>moves the sprite to the bottom layer</i><br>
 
483
  <tt>LayeredUpdates.move_to_back(sprite): return None</tt><br>
 
484
<p>Moves the sprite to the bottom layer, moving it behind all other layers and adding one additional layer. </p>
 
485
<!--COMMENTS:LayeredUpdates.move_to_back--> &nbsp;<br> 
 
486
<br></ul>
 
487
 
 
488
 
 
489
<a name="LayeredUpdates.get_top_sprite">
 
490
<big><b>LayeredUpdates.get_top_sprite</big></b><br><ul>
 
491
  <i>returns the topmost sprite</i><br>
 
492
  <tt>LayeredUpdates.get_top_sprite(): return Sprite</tt><br>
 
493
 &nbsp;<br> 
 
494
<!--COMMENTS:LayeredUpdates.get_top_sprite--> &nbsp;<br> 
 
495
<br></ul>
 
496
 
 
497
 
 
498
<a name="LayeredUpdates.get_sprites_from_layer">
 
499
<big><b>LayeredUpdates.get_sprites_from_layer</big></b><br><ul>
 
500
  <i>returns all sprites from a layer, ordered by how they where added</i><br>
 
501
  <tt>LayeredUpdates.get_sprites_from_layer(layer): return sprites</tt><br>
 
502
<p>Returns all sprites from a layer, ordered by how they where added. It uses linear search and the sprites are not removed from layer. </p>
 
503
<!--COMMENTS:LayeredUpdates.get_sprites_from_layer--> &nbsp;<br> 
 
504
<br></ul>
 
505
 
 
506
 
 
507
<a name="LayeredUpdates.switch_layer">
 
508
<big><b>LayeredUpdates.switch_layer</big></b><br><ul>
 
509
  <i>switches the sprites from layer1 to layer2</i><br>
 
510
  <tt>LayeredUpdates.switch_layer(layer1_nr, layer2_nr): return None</tt><br>
 
511
<p>The layers number must exist, it is not checked. </p>
 
512
<!--COMMENTS:LayeredUpdates.switch_layer--> &nbsp;<br> 
 
513
<br></ul>
 
514
<br></ul>
 
515
 
 
516
 
 
517
<a name="pygame.sprite.LayeredDirty">
 
518
<big><b>pygame.sprite.LayeredDirty</big></b><br><ul>
 
519
  <i>LayeredDirty Group is for DirtySprites.  Subclasses LayeredUpdates.</i><br>
 
520
  <tt>pygame.sprite.LayeredDirty(*spites, **kwargs): return LayeredDirty</tt><br>
 
521
<ul><small><table>
 
522
  <tr><td><a href="sprite.html#LayeredDirty.draw">LayeredDirty.draw</a> - <font size=-1>draw all sprites in the right order onto the passed surface.</font></td><td>draw all sprites in the right order onto the passed surface.</td></tr>
 
523
  <tr><td><a href="sprite.html#LayeredDirty.clear">LayeredDirty.clear</a> - <font size=-1>used to set background</font></td><td>used to set background</td></tr>
 
524
  <tr><td><a href="sprite.html#LayeredDirty.repaint_rect">LayeredDirty.repaint_rect</a> - <font size=-1>repaints the given area</font></td><td>repaints the given area</td></tr>
 
525
  <tr><td><a href="sprite.html#LayeredDirty.set_clip">LayeredDirty.set_clip</a> - <font size=-1>clip the area where to draw. Just pass None (default) to reset the clip</font></td><td>clip the area where to draw. Just pass None (default) to reset the clip</td></tr>
 
526
  <tr><td><a href="sprite.html#LayeredDirty.get_clip">LayeredDirty.get_clip</a> - <font size=-1>clip the area where to draw. Just pass None (default) to reset the clip</font></td><td>clip the area where to draw. Just pass None (default) to reset the clip</td></tr>
 
527
  <tr><td><a href="sprite.html#LayeredDirty.change_layer">LayeredDirty.change_layer</a> - <font size=-1>changes the layer of the sprite</font></td><td>changes the layer of the sprite</td></tr>
 
528
  <tr><td><a href="sprite.html#LayeredDirty.set_timing_treshold">LayeredDirty.set_timing_treshold</a> - <font size=-1>sets the treshold in milliseconds</font></td><td>sets the treshold in milliseconds</td></tr>
 
529
</table></small></ul>
 
530
<p>This group requires <tt>pygame.sprite.DirtySprite</tt> or any sprite that has the following attributes: </p>
 
531
<pre>    image, rect, dirty, visible, blendmode (see doc of DirtySprite).
 
532
</pre><p>It uses the dirty flag technique and is therefore faster than the <tt>pygame.sprite.RenderUpdates</tt> if you have many static sprites. It also switches automatically between dirty rect update and full screen drawing, so you do no have to worry what would be faster. </p>
 
533
<p>Same as for the <tt>pygame.sprite.Group</tt>. You can specify some additional attributes through kwargs: </p>
 
534
<pre>    _use_update: True/False   default is False
 
535
    _default_layer: default layer where sprites without a layer are added.
 
536
    _time_threshold: treshold time for switching between dirty rect mode
 
537
        and fullscreen mode, defaults to 1000./80  == 1000./fps
 
538
</pre><p>New in pygame <tt>1.8.0</tt> </p>
 
539
<!--COMMENTS:pygame.sprite.LayeredDirty--> &nbsp;<br> 
 
540
 
 
541
 
 
542
<a name="LayeredDirty.draw">
 
543
<big><b>LayeredDirty.draw</big></b><br><ul>
 
544
  <i>draw all sprites in the right order onto the passed surface.</i><br>
 
545
  <tt>LayeredDirty.draw(surface, bgd=None): return Rect_list</tt><br>
 
546
<p>You can pass the background too. If a background is already set, then the bgd argument has no effect. </p>
 
547
<!--COMMENTS:LayeredDirty.draw--> &nbsp;<br> 
 
548
<br></ul>
 
549
 
 
550
 
 
551
<a name="LayeredDirty.clear">
 
552
<big><b>LayeredDirty.clear</big></b><br><ul>
 
553
  <i>used to set background</i><br>
 
554
  <tt>LayeredDirty.clear(surface, bgd): return None</tt><br>
 
555
 &nbsp;<br> 
 
556
<!--COMMENTS:LayeredDirty.clear--> &nbsp;<br> 
 
557
<br></ul>
 
558
 
 
559
 
 
560
<a name="LayeredDirty.repaint_rect">
 
561
<big><b>LayeredDirty.repaint_rect</big></b><br><ul>
 
562
  <i>repaints the given area</i><br>
 
563
  <tt>LayeredDirty.repaint_rect(screen_rect): return None</tt><br>
 
564
<p>screen_rect is in screencoordinates. </p>
 
565
<!--COMMENTS:LayeredDirty.repaint_rect--> &nbsp;<br> 
 
566
<br></ul>
 
567
 
 
568
 
 
569
<a name="LayeredDirty.set_clip">
 
570
<big><b>LayeredDirty.set_clip</big></b><br><ul>
 
571
  <i>clip the area where to draw. Just pass None (default) to reset the clip</i><br>
 
572
  <tt>LayeredDirty.set_clip(screen_rect=None): return None</tt><br>
 
573
 &nbsp;<br> 
 
574
<!--COMMENTS:LayeredDirty.set_clip--> &nbsp;<br> 
 
575
<br></ul>
 
576
 
 
577
 
 
578
<a name="LayeredDirty.get_clip">
 
579
<big><b>LayeredDirty.get_clip</big></b><br><ul>
 
580
  <i>clip the area where to draw. Just pass None (default) to reset the clip</i><br>
 
581
  <tt>LayeredDirty.get_clip(): return Rect</tt><br>
 
582
 &nbsp;<br> 
 
583
<!--COMMENTS:LayeredDirty.get_clip--> &nbsp;<br> 
 
584
<br></ul>
 
585
 
 
586
 
 
587
<a name="LayeredDirty.change_layer">
 
588
<big><b>LayeredDirty.change_layer</big></b><br><ul>
 
589
  <i>changes the layer of the sprite</i><br>
 
590
  <tt>change_layer(sprite, new_layer): return None</tt><br>
 
591
<p>sprite must have been added to the renderer. It is not checked. </p>
 
592
<!--COMMENTS:LayeredDirty.change_layer--> &nbsp;<br> 
 
593
<br></ul>
 
594
 
 
595
 
 
596
<a name="LayeredDirty.set_timing_treshold">
 
597
<big><b>LayeredDirty.set_timing_treshold</big></b><br><ul>
 
598
  <i>sets the treshold in milliseconds</i><br>
 
599
  <tt>set_timing_treshold(time_ms): return None</tt><br>
 
600
<p>Default is <tt>1000./80</tt> where 80 is the fps <tt>I</tt> want to switch to full screen mode. </p>
 
601
<!--COMMENTS:LayeredDirty.set_timing_treshold--> &nbsp;<br> 
 
602
<br></ul>
 
603
<br></ul>
 
604
 
 
605
 
 
606
<a name="pygame.sprite.GroupSingle">
 
607
<big><b>pygame.sprite.GroupSingle</big></b><br><ul>
 
608
  <i>Group container that holds a single Sprite</i><br>
 
609
  <tt>pygame.sprite.GroupSingle(sprite=None): return GroupSingle</tt><br>
 
610
<p>The GroupSingle container only holds a single Sprite. When a new Sprite is added, the old one is removed. </p>
 
611
<p>There is a special property, <tt>GroupSingle.sprite</tt>, that accesses the Sprite that this Group contains. It can be None when the Group is empty. The property can also be assigned to add a Sprite into the GroupSingle container. </p>
 
612
<!--COMMENTS:pygame.sprite.GroupSingle--> &nbsp;<br> 
 
613
<br></ul>
 
614
 
 
615
 
 
616
<a name="pygame.sprite.spritecollide">
 
617
<big><b>pygame.sprite.spritecollide</big></b><br><ul>
 
618
  <i>find Sprites in a Group that intersect another Sprite</i><br>
 
619
  <tt>pygame.sprite.spritecollide(sprite, group, dokill, collided = None): return Sprite_list</tt><br>
 
620
<p>Return a list containing all Sprites in a Group that intersect with another Sprite. Intersection is determined by comparing the <tt>Sprite.rect</tt> attribute of each Sprite. </p>
 
621
<p>The dokill argument is a bool. If set to True, all Sprites that collide will be removed from the Group. </p>
 
622
<p>The collided argument is a callback function used to calculate if two sprites are colliding. it should take two sprites as values, and return a bool value indicating if they are colliding. If collided is not passed, all sprites must have a "rect" value, which is a rectangle of the sprite area, which will be used to calculate the collision. </p>
 
623
<p>collided callables: </p>
 
624
<pre>    collide_rect, collide_rect_ratio, collide_circle,
 
625
    collide_circle_ratio, collide_mask
 
626
</pre>
 
627
<!--COMMENTS:pygame.sprite.spritecollide--> &nbsp;<br> 
 
628
<br></ul>
 
629
 
 
630
 
 
631
<a name="pygame.sprite.collide_rect">
 
632
<big><b>pygame.sprite.collide_rect</big></b><br><ul>
 
633
  <i>collision detection between two sprites, using rects.</i><br>
 
634
  <tt>pygame.sprite.collide_rect(left, right): return bool</tt><br>
 
635
<p>Tests for collision between two sprites. Uses the pygame rect colliderect function to calculate the collision. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" attributes. </p>
 
636
<p>New in pygame <tt>1.8.0</tt> </p>
 
637
<!--COMMENTS:pygame.sprite.collide_rect--> &nbsp;<br> 
 
638
<br></ul>
 
639
 
 
640
 
 
641
<a name="pygame.sprite.collide_rect_ratio">
 
642
<big><b>pygame.sprite.collide_rect_ratio</big></b><br><ul>
 
643
  <i>collision detection between two sprites, using rects scaled to a ratio.</i><br>
 
644
  <tt>pygame.sprite.collide_rect_ratio(ratio): return collided_callable</tt><br>
 
645
<p><tt>A</tt> callable class that checks for collisions between two sprites, using a scaled version of the sprites rects. </p>
 
646
<p>Is created with a ratio, the instance is then intended to be passed as a collided callback function to the *collide functions. </p>
 
647
<p><tt>A</tt> ratio is a floating point number - <tt>1.0</tt> is the same size, <tt>2.0</tt> is twice as big, and <tt>0.5</tt> is half the size. </p>
 
648
<p>New in pygame <tt>1.8.1</tt> </p>
 
649
<!--COMMENTS:pygame.sprite.collide_rect_ratio--> &nbsp;<br> 
 
650
<br></ul>
 
651
 
 
652
 
 
653
<a name="pygame.sprite.collide_circle">
 
654
<big><b>pygame.sprite.collide_circle</big></b><br><ul>
 
655
  <i>collision detection between two sprites, using circles.</i><br>
 
656
  <tt>pygame.sprite.collide_circle(left, right): return bool</tt><br>
 
657
<p>Tests for collision between two sprites, by testing to see if two circles centered on the sprites overlap. If the sprites have a "radius" attribute, that is used to create the circle, otherwise a circle is created that is big enough to completely enclose the sprites rect as given by the "rect" attribute. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" and an optional "radius" attribute. </p>
 
658
<p>New in pygame <tt>1.8.1</tt> </p>
 
659
<!--COMMENTS:pygame.sprite.collide_circle--> &nbsp;<br> 
 
660
<br></ul>
 
661
 
 
662
 
 
663
<a name="pygame.sprite.collide_circle_ratio">
 
664
<big><b>pygame.sprite.collide_circle_ratio</big></b><br><ul>
 
665
  <i>collision detection between two sprites, using circles scaled to a ratio.</i><br>
 
666
  <tt>pygame.sprite.collide_circle_ratio(ratio): return collided_callable</tt><br>
 
667
<p><tt>A</tt> callable class that checks for collisions between two sprites, using a scaled version of the sprites radius. </p>
 
668
<p>Is created with a floating point ratio, the instance is then intended to be passed as a collided callback function to the *collide functions. </p>
 
669
<p><tt>A</tt> ratio is a floating point number - <tt>1.0</tt> is the same size, <tt>2.0</tt> is twice as big, and <tt>0.5</tt> is half the size. </p>
 
670
<p>The created callable tests for collision between two sprites, by testing to see if two circles centered on the sprites overlap, after scaling the circles radius by the stored ratio. If the sprites have a "radius" attribute, that is used to create the circle, otherwise a circle is created that is big enough to completely enclose the sprites rect as given by the "rect" attribute. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" and an optional "radius" attribute. </p>
 
671
<p>New in pygame <tt>1.8.1</tt> </p>
 
672
<!--COMMENTS:pygame.sprite.collide_circle_ratio--> &nbsp;<br> 
 
673
<br></ul>
 
674
 
 
675
 
 
676
<a name="pygame.sprite.collide_mask">
 
677
<big><b>pygame.sprite.collide_mask</big></b><br><ul>
 
678
  <i>collision detection between two sprites, using masks.</i><br>
 
679
  <tt>pygame.sprite.collide_mask(SpriteLeft, SpriteRight): return bool</tt><br>
 
680
<p>Tests for collision between two sprites, by testing if thier bitmasks overlap. If the sprites have a "mask" attribute, that is used as the mask, otherwise a mask is created from the sprite image. Intended to be passed as a collided callback function to the *collide functions. Sprites must have a "rect" and an optional "mask" attribute. </p>
 
681
<p>New in pygame <tt>1.8.0</tt> </p>
 
682
<!--COMMENTS:pygame.sprite.collide_mask--> &nbsp;<br> 
 
683
<br></ul>
 
684
 
 
685
 
 
686
<a name="pygame.sprite.groupcollide">
 
687
<big><b>pygame.sprite.groupcollide</big></b><br><ul>
 
688
  <i>find all Sprites that collide between two Groups</i><br>
 
689
  <tt>pygame.sprite.groupcollide(group1, group2, dokill1, dokill2): return Sprite_dict</tt><br>
 
690
<p>This will find intersections between all the Sprites in two groups. Intersection is determined by comparing the <tt>Sprite.rect</tt> attribute of each Sprite. </p>
 
691
<p>Every Sprite inside group1 is added to the return dictionary. The value for each item is the list of Sprites in group2 that intersect. </p>
 
692
<p>If either dokill argument is True, the intersecting Sprites will be removed from their respective Group. </p>
 
693
<!--COMMENTS:pygame.sprite.groupcollide--> &nbsp;<br> 
 
694
<br></ul>
 
695
 
 
696
 
 
697
<a name="pygame.sprite.spritecollideany">
 
698
<big><b>pygame.sprite.spritecollideany</big></b><br><ul>
 
699
  <i>simple test if a Sprite intersects anything in a Group</i><br>
 
700
  <tt>pygame.sprite.spritecollideany(sprite, group): return bool</tt><br>
 
701
<p>Test if the given Sprite intersects with any Sprites in a Group. Intersection is determined by comparing of the <tt>Sprite.rect</tt> attribute of each Sprite. </p>
 
702
<p>This collision test can be faster than <tt><a href="sprite.html#pygame.sprite.spritecollide">pygame.sprite.spritecollide</a> - <font size=-1>find Sprites in a Group that intersect another Sprite</font></tt> since it has less work to do. </p>
 
703
<!--COMMENTS:pygame.sprite.spritecollideany--> &nbsp;<br> 
 
704
<br></ul>
 
705
 
 
706
 
 
707
<a name="">
 
708
<big><b></big></b><br><ul>
 
709
 &nbsp;<br> 
 
710
<!--COMMENTS:--> &nbsp;<br> 
 
711
<br></ul>
 
712
<br></ul>
 
713
 
 
714
</body></html>