Mercurial > pygame
annotate docs/ref/sprite.html @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | 5f97207c3692 |
| children |
| rev | line source |
|---|---|
| 3145 | 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| 2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
| 3 | |
| 4 <html xmlns="http://www.w3.org/1999/xhtml"> | |
| 5 <head> | |
| 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
| 7 | |
| 8 <title>pygame.sprite — Pygame v1.9.2 documentation</title> | |
| 9 <link rel="stylesheet" href="../_static/pygame.css" type="text/css" /> | |
| 10 <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> | |
| 11 <script type="text/javascript"> | |
| 12 var DOCUMENTATION_OPTIONS = { | |
| 13 URL_ROOT: '../', | |
| 14 VERSION: '1.9.2', | |
| 15 COLLAPSE_INDEX: false, | |
| 16 FILE_SUFFIX: '.html', | |
| 17 HAS_SOURCE: true | |
| 18 }; | |
| 19 </script> | |
| 20 <script type="text/javascript" src="../_static/jquery.js"></script> | |
| 21 <script type="text/javascript" src="../_static/underscore.js"></script> | |
| 22 <script type="text/javascript" src="../_static/doctools.js"></script> | |
| 23 <link rel="shortcut icon" href="../_static/pygame.ico"/> | |
| 24 <link rel="top" title="Pygame v1.9.2 documentation" href="../index.html" /> | |
| 25 <link rel="next" title="pygame.Surface" href="surface.html" /> | |
| 26 <link rel="prev" title="pygame.sndarray" href="sndarray.html" /> | |
| 27 </head> | |
| 28 <body> | |
| 29 | |
| 30 <div class="document"> | |
| 31 | |
| 32 <div class="header"> | |
| 33 <table> | |
| 34 <tr> | |
| 35 <td class="logo"> | |
| 36 <a href="http://www.pygame.org/"> | |
| 37 <img src="../_static/pygame_tiny.png"/> | |
| 38 </a> | |
| 39 <h5>pygame documentation</h5> | |
| 40 </td> | |
| 41 <td class="pagelinks"> | |
| 42 <p class="top"> | |
| 43 || | |
| 44 <a href="http://www.pygame.org/">Pygame Home</a> || | |
| 45 <a href="../index.html">Help Contents</a> || | |
| 46 <a href="../genindex.html">Reference Index</a> || | |
| 47 </p> | |
| 48 <p class="bottom"> | |
| 49 <a href="camera.html">camera</a> || | |
| 50 <a href="cdrom.html">cdrom</a> || | |
| 51 <a href="color.html">Color</a> || | |
| 52 <a href="cursors.html">cursors</a> || | |
| 53 <a href="display.html">display</a> || | |
| 54 <a href="draw.html">draw</a> || | |
| 55 <a href="event.html">event</a> || | |
| 56 <a href="examples.html">examples</a> || | |
| 57 <a href="font.html">font</a> || | |
| 58 <a href="freetype.html">freetype</a> || | |
| 59 <a href="gfxdraw.html">gfxdraw</a> || | |
| 60 <a href="image.html">image</a> || | |
| 61 <a href="joystick.html">joystick</a> || | |
| 62 <a href="key.html">key</a> || | |
| 63 <a href="locals.html">locals</a> || | |
| 64 <a href="mask.html">mask</a> || | |
| 65 <a href="math.html">math</a> || | |
| 66 <a href="midi.html">midi</a> || | |
| 67 <a href="mixer.html">mixer</a> || | |
| 68 <a href="mouse.html">mouse</a> || | |
| 69 <a href="movie.html">movie</a> || | |
| 70 <a href="music.html">music</a> || | |
| 71 <a href="overlay.html">Overlay</a> || | |
| 72 <a href="pixelarray.html">PixelArray</a> || | |
| 73 <a href="pixelcopy.html">pixelcopy</a> || | |
| 74 <a href="pygame.html">pygame</a> || | |
| 75 <a href="rect.html">Rect</a> || | |
| 76 <a href="scrap.html">scrap</a> || | |
| 77 <a href="sndarray.html">sndarray</a> || | |
| 78 <a href="sprite.html">sprite</a> || | |
| 79 <a href="surface.html">Surface</a> || | |
| 80 <a href="surfarray.html">surfarray</a> || | |
| 81 <a href="tests.html">tests</a> || | |
| 82 <a href="time.html">time</a> || | |
| 83 <a href="transform.html">transform</a> || | |
| 84 <a href="pygame.html#module-pygame.version">version</a> | |
| 85 </p> | |
| 86 </td> | |
| 87 </tr> | |
| 88 </table> | |
| 89 </div> | |
| 90 | |
| 91 <div class="documentwrapper"> | |
| 92 <div class="body"> | |
| 93 | |
| 94 <div class="sectionwrapper"> | |
| 95 <div class="section" id="module-pygame.sprite"> | |
| 96 <span id="pygame-sprite"></span><dl class="definition module"> | |
| 97 <dt class="title module"> | |
| 98 <tt class="docutils literal"><span class="pre">pygame.sprite</span></tt></dt> | |
| 99 <dd><div class="line-block"> | |
| 100 <div class="line"><span class="summaryline">pygame module with basic game object classes</span></div> | |
| 101 </div> | |
| 102 <table border="1" class="toc docutils"> | |
| 103 <colgroup> | |
| 104 <col width="30%" /> | |
| 105 <col width="1%" /> | |
| 106 <col width="69%" /> | |
| 107 </colgroup> | |
| 108 <tbody valign="top"> | |
| 109 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite">pygame.sprite.Sprite</a></td> | |
| 110 <td>—</td> | |
| 111 <td>simple base class for visible game objects</td> | |
| 112 </tr> | |
| 113 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.DirtySprite">pygame.sprite.DirtySprite</a></td> | |
| 114 <td>—</td> | |
| 115 <td>a more featureful subclass of Sprite with more attributes</td> | |
| 116 </tr> | |
| 117 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Group">pygame.sprite.Group</a></td> | |
| 118 <td>—</td> | |
| 119 <td>container class for many Sprites</td> | |
| 120 </tr> | |
| 121 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.RenderPlain">pygame.sprite.RenderPlain</a></td> | |
| 122 <td>—</td> | |
| 123 <td></td> | |
| 124 </tr> | |
| 125 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.RenderClear">pygame.sprite.RenderClear</a></td> | |
| 126 <td>—</td> | |
| 127 <td></td> | |
| 128 </tr> | |
| 129 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.RenderUpdates">pygame.sprite.RenderUpdates</a></td> | |
| 130 <td>—</td> | |
| 131 <td>Group class that tracks dirty updates</td> | |
| 132 </tr> | |
| 133 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.OrderedUpdates">pygame.sprite.OrderedUpdates</a></td> | |
| 134 <td>—</td> | |
| 135 <td>RenderUpdates class that draws Sprites in order of addition</td> | |
| 136 </tr> | |
| 137 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates">pygame.sprite.LayeredUpdates</a></td> | |
| 138 <td>—</td> | |
| 139 <td>LayeredUpdates Group handles layers, that draws like OrderedUpdates.</td> | |
| 140 </tr> | |
| 141 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty">pygame.sprite.LayeredDirty</a></td> | |
| 142 <td>—</td> | |
| 143 <td>LayeredDirty Group is for DirtySprites. Subclasses LayeredUpdates.</td> | |
| 144 </tr> | |
| 145 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.GroupSingle">pygame.sprite.GroupSingle</a></td> | |
| 146 <td>—</td> | |
| 147 <td>Group container that holds a single Sprite</td> | |
| 148 </tr> | |
| 149 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.spritecollide">pygame.sprite.spritecollide</a></td> | |
| 150 <td>—</td> | |
| 151 <td>find Sprites in a Group that intersect another Sprite</td> | |
| 152 </tr> | |
| 153 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.collide_rect">pygame.sprite.collide_rect</a></td> | |
| 154 <td>—</td> | |
| 155 <td>collision detection between two sprites, using rects.</td> | |
| 156 </tr> | |
| 157 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.collide_rect_ratio">pygame.sprite.collide_rect_ratio</a></td> | |
| 158 <td>—</td> | |
| 159 <td>collision detection between two sprites, using rects scaled to a ratio.</td> | |
| 160 </tr> | |
| 161 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.collide_circle">pygame.sprite.collide_circle</a></td> | |
| 162 <td>—</td> | |
| 163 <td>collision detection between two sprites, using circles.</td> | |
| 164 </tr> | |
| 165 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.collide_circle_ratio">pygame.sprite.collide_circle_ratio</a></td> | |
| 166 <td>—</td> | |
| 167 <td>collision detection between two sprites, using circles scaled to a ratio.</td> | |
| 168 </tr> | |
| 169 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.collide_mask">pygame.sprite.collide_mask</a></td> | |
| 170 <td>—</td> | |
| 171 <td>collision detection between two sprites, using masks.</td> | |
| 172 </tr> | |
| 173 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.groupcollide">pygame.sprite.groupcollide</a></td> | |
| 174 <td>—</td> | |
| 175 <td>find all Sprites that collide between two Groups</td> | |
| 176 </tr> | |
| 177 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.spritecollideany">pygame.sprite.spritecollideany</a></td> | |
| 178 <td>—</td> | |
| 179 <td>simple test if a Sprite intersects anything in a Group</td> | |
| 180 </tr> | |
| 181 </tbody> | |
| 182 </table> | |
| 183 <p>This module contains several simple classes to be used within games. There is | |
| 184 the main Sprite class and several Group classes that contain Sprites. The use | |
| 185 of these classes is entirely optional when using Pygame. The classes are fairly | |
| 186 lightweight and only provide a starting place for the code that is common to | |
| 187 most games.</p> | |
| 188 <p>The Sprite class is intended to be used as a base class for the different types | |
| 189 of objects in the game. There is also a base Group class that simply stores | |
| 190 sprites. A game could create new types of Group classes that operate on | |
| 191 specially customized Sprite instances they contain.</p> | |
| 192 <p>The basic Sprite class can draw the Sprites it contains to a Surface. The | |
| 193 <tt class="docutils literal"><span class="pre">Group.draw()</span></tt> method requires that each Sprite have a <tt class="docutils literal"><span class="pre">Surface.image</span></tt> | |
| 194 attribute and a <tt class="docutils literal"><span class="pre">Surface.rect</span></tt>. The <tt class="docutils literal"><span class="pre">Group.clear()</span></tt> method requires these | |
| 195 same attributes, and can be used to erase all the Sprites with background. | |
| 196 There are also more advanced Groups: <tt class="docutils literal"><span class="pre">pygame.sprite.RenderUpdates()</span></tt> and | |
| 197 <tt class="docutils literal"><span class="pre">pygame.sprite.OrderedUpdates()</span></tt>.</p> | |
| 198 <p>Lastly, this module contains several collision functions. These help find | |
| 199 sprites inside multiple groups that have intersecting bounding rectangles. To | |
| 200 find the collisions, the Sprites are required to have a <tt class="docutils literal"><span class="pre">Surface.rect</span></tt> | |
| 201 attribute assigned.</p> | |
| 202 <p>The groups are designed for high efficiency in removing and adding Sprites to | |
| 203 them. They also allow cheap testing to see if a Sprite already exists in a | |
| 204 Group. A given Sprite can exist in any number of groups. A game could use some | |
| 205 groups to control object rendering, and a completely separate set of groups to | |
| 206 control interaction or player movement. Instead of adding type attributes or | |
| 207 bools to a derived Sprite class, consider keeping the Sprites inside organized | |
| 208 Groups. This will allow for easier lookup later in the game.</p> | |
| 209 <p>Sprites and Groups manage their relationships with the <tt class="docutils literal"><span class="pre">add()</span></tt> and | |
| 210 <tt class="docutils literal"><span class="pre">remove()</span></tt> methods. These methods can accept a single or multiple targets for | |
| 211 membership. The default initializers for these classes also takes a single or | |
| 212 list of targets for initial membership. It is safe to repeatedly add and remove | |
| 213 the same Sprite from a Group.</p> | |
| 214 <p>While it is possible to design sprite and group classes that don’t derive from | |
| 215 the Sprite and AbstractGroup classes below, it is strongly recommended that you | |
| 216 extend those when you add a Sprite or Group class.</p> | |
| 217 <p>Sprites are not thread safe. So lock them yourself if using threads.</p> | |
| 218 <dl class="definition class"> | |
| 219 <dt class="title" id="pygame.sprite.Sprite"> | |
| 220 <em class="property">class </em><tt class="descclassname">pygame.sprite.</tt><tt class="descname">Sprite</tt><a class="headerlink" href="#pygame.sprite.Sprite" title="Permalink to this definition">¶</a></dt> | |
| 221 <dd><div class="line-block"> | |
| 222 <div class="line"><span class="summaryline">simple base class for visible game objects</span></div> | |
| 223 <div class="line"><span class="signature">Sprite(*groups) -> Sprite</span></div> | |
| 224 </div> | |
| 225 <table border="1" class="toc docutils"> | |
| 226 <colgroup> | |
| 227 <col width="37%" /> | |
| 228 <col width="1%" /> | |
| 229 <col width="62%" /> | |
| 230 </colgroup> | |
| 231 <tbody valign="top"> | |
| 232 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite.update">pygame.sprite.Sprite.update</a></td> | |
| 233 <td>—</td> | |
| 234 <td>method to control sprite behavior</td> | |
| 235 </tr> | |
| 236 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite.add">pygame.sprite.Sprite.add</a></td> | |
| 237 <td>—</td> | |
| 238 <td>add the sprite to groups</td> | |
| 239 </tr> | |
| 240 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite.remove">pygame.sprite.Sprite.remove</a></td> | |
| 241 <td>—</td> | |
| 242 <td>remove the sprite from groups</td> | |
| 243 </tr> | |
| 244 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite.kill">pygame.sprite.Sprite.kill</a></td> | |
| 245 <td>—</td> | |
| 246 <td>remove the Sprite from all Groups</td> | |
| 247 </tr> | |
| 248 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite.alive">pygame.sprite.Sprite.alive</a></td> | |
| 249 <td>—</td> | |
| 250 <td>does the sprite belong to any groups</td> | |
| 251 </tr> | |
| 252 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite.groups">pygame.sprite.Sprite.groups</a></td> | |
| 253 <td>—</td> | |
| 254 <td>list of Groups that contain this Sprite</td> | |
| 255 </tr> | |
| 256 </tbody> | |
| 257 </table> | |
| 258 <p>The base class for visible game objects. Derived classes will want to | |
| 259 override the <tt class="docutils literal"><span class="pre">Sprite.update()</span></tt> and assign a <tt class="docutils literal"><span class="pre">Sprite.image</span></tt> and | |
| 260 <tt class="docutils literal"><span class="pre">Sprite.rect</span></tt> attributes. The initializer can accept any number of Group | |
| 261 instances to be added to.</p> | |
| 262 <p>When subclassing the Sprite, be sure to call the base initializer before | |
| 263 adding the Sprite to Groups.</p> | |
| 264 <dl class="definition method"> | |
| 265 <dt class="title" id="pygame.sprite.Sprite.update"> | |
| 266 <tt class="descname">update</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Sprite.update" title="Permalink to this definition">¶</a></dt> | |
| 267 <dd><div class="line-block"> | |
| 268 <div class="line"><span class="summaryline">method to control sprite behavior</span></div> | |
| 269 <div class="line"><span class="signature">update(*args) -> None</span></div> | |
| 270 </div> | |
| 271 <p>The default implementation of this method does nothing; it’s just a | |
| 272 convenient “hook” that you can override. This method is called by | |
| 273 <tt class="docutils literal"><span class="pre">Group.update()</span></tt> with whatever arguments you give it.</p> | |
| 274 <p>There is no need to use this method if not using the convenience method | |
| 275 by the same name in the Group class.</p> | |
| 276 </dd></dl> | |
| 277 | |
| 278 <dl class="definition method"> | |
| 279 <dt class="title" id="pygame.sprite.Sprite.add"> | |
| 280 <tt class="descname">add</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Sprite.add" title="Permalink to this definition">¶</a></dt> | |
| 281 <dd><div class="line-block"> | |
| 282 <div class="line"><span class="summaryline">add the sprite to groups</span></div> | |
| 283 <div class="line"><span class="signature">add(*groups) -> None</span></div> | |
| 284 </div> | |
| 285 <p>Any number of Group instances can be passed as arguments. The Sprite will | |
| 286 be added to the Groups it is not already a member of.</p> | |
| 287 </dd></dl> | |
| 288 | |
| 289 <dl class="definition method"> | |
| 290 <dt class="title" id="pygame.sprite.Sprite.remove"> | |
| 291 <tt class="descname">remove</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Sprite.remove" title="Permalink to this definition">¶</a></dt> | |
| 292 <dd><div class="line-block"> | |
| 293 <div class="line"><span class="summaryline">remove the sprite from groups</span></div> | |
| 294 <div class="line"><span class="signature">remove(*groups) -> None</span></div> | |
| 295 </div> | |
| 296 <p>Any number of Group instances can be passed as arguments. The Sprite will | |
| 297 be removed from the Groups it is currently a member of.</p> | |
| 298 </dd></dl> | |
| 299 | |
| 300 <dl class="definition method"> | |
| 301 <dt class="title" id="pygame.sprite.Sprite.kill"> | |
| 302 <tt class="descname">kill</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Sprite.kill" title="Permalink to this definition">¶</a></dt> | |
| 303 <dd><div class="line-block"> | |
| 304 <div class="line"><span class="summaryline">remove the Sprite from all Groups</span></div> | |
| 305 <div class="line"><span class="signature">kill() -> None</span></div> | |
| 306 </div> | |
| 307 <p>The Sprite is removed from all the Groups that contain it. This won’t | |
| 308 change anything about the state of the Sprite. It is possible to continue | |
| 309 to use the Sprite after this method has been called, including adding it | |
| 310 to Groups.</p> | |
| 311 </dd></dl> | |
| 312 | |
| 313 <dl class="definition method"> | |
| 314 <dt class="title" id="pygame.sprite.Sprite.alive"> | |
| 315 <tt class="descname">alive</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Sprite.alive" title="Permalink to this definition">¶</a></dt> | |
| 316 <dd><div class="line-block"> | |
| 317 <div class="line"><span class="summaryline">does the sprite belong to any groups</span></div> | |
| 318 <div class="line"><span class="signature">alive() -> bool</span></div> | |
| 319 </div> | |
| 320 <p>Returns True when the Sprite belongs to one or more Groups.</p> | |
| 321 </dd></dl> | |
| 322 | |
| 323 <dl class="definition method"> | |
| 324 <dt class="title" id="pygame.sprite.Sprite.groups"> | |
| 325 <tt class="descname">groups</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Sprite.groups" title="Permalink to this definition">¶</a></dt> | |
| 326 <dd><div class="line-block"> | |
| 327 <div class="line"><span class="summaryline">list of Groups that contain this Sprite</span></div> | |
| 328 <div class="line"><span class="signature">groups() -> group_list</span></div> | |
| 329 </div> | |
| 330 <p>Return a list of all the Groups that contain this Sprite.</p> | |
| 331 </dd></dl> | |
| 332 | |
| 333 </dd></dl> | |
| 334 | |
| 335 <dl class="definition class"> | |
| 336 <dt class="title" id="pygame.sprite.DirtySprite"> | |
| 337 <em class="property">class </em><tt class="descclassname">pygame.sprite.</tt><tt class="descname">DirtySprite</tt><a class="headerlink" href="#pygame.sprite.DirtySprite" title="Permalink to this definition">¶</a></dt> | |
| 338 <dd><div class="line-block"> | |
| 339 <div class="line"><span class="summaryline">a more featureful subclass of Sprite with more attributes</span></div> | |
| 340 <div class="line"><span class="signature">DirtySprite(*groups) -> DirtySprite</span></div> | |
| 341 </div> | |
| 342 <p>Extra DirtySprite attributes with their default values:</p> | |
| 343 <p>dirty = 1</p> | |
| 344 <div class="highlight-python"><pre>if set to 1, it is repainted and then set to 0 again | |
| 345 if set to 2 then it is always dirty ( repainted each frame, | |
| 346 flag is not reset) | |
| 347 0 means that it is not dirty and therefor not repainted again</pre> | |
| 348 </div> | |
| 349 <p>blendmode = 0</p> | |
| 350 <div class="highlight-python"><pre>its the special_flags argument of blit, blendmodes</pre> | |
| 351 </div> | |
| 352 <p>source_rect = None</p> | |
| 353 <div class="highlight-python"><pre>source rect to use, remember that it is relative to | |
| 354 topleft (0,0) of self.image</pre> | |
| 355 </div> | |
| 356 <p>visible = 1</p> | |
| 357 <div class="highlight-python"><pre>normally 1, if set to 0 it will not be repainted | |
| 358 (you must set it dirty too to be erased from screen)</pre> | |
| 359 </div> | |
| 360 <p>layer = 0</p> | |
| 361 <div class="highlight-python"><pre>(READONLY value, it is read when adding it to the | |
| 362 LayeredDirty, for details see doc of LayeredDirty)</pre> | |
| 363 </div> | |
| 364 </dd></dl> | |
| 365 | |
| 366 <dl class="definition class"> | |
| 367 <dt class="title" id="pygame.sprite.Group"> | |
| 368 <em class="property">class </em><tt class="descclassname">pygame.sprite.</tt><tt class="descname">Group</tt><a class="headerlink" href="#pygame.sprite.Group" title="Permalink to this definition">¶</a></dt> | |
| 369 <dd><div class="line-block"> | |
| 370 <div class="line"><span class="summaryline">container class for many Sprites</span></div> | |
| 371 <div class="line"><span class="signature">Group(*sprites) -> Group</span></div> | |
| 372 </div> | |
| 373 <table border="1" class="toc docutils"> | |
| 374 <colgroup> | |
| 375 <col width="35%" /> | |
| 376 <col width="1%" /> | |
| 377 <col width="64%" /> | |
| 378 </colgroup> | |
| 379 <tbody valign="top"> | |
| 380 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Group.sprites">pygame.sprite.Group.sprites</a></td> | |
| 381 <td>—</td> | |
| 382 <td>list of the Sprites this Group contains</td> | |
| 383 </tr> | |
| 384 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Group.copy">pygame.sprite.Group.copy</a></td> | |
| 385 <td>—</td> | |
| 386 <td>duplicate the Group</td> | |
| 387 </tr> | |
| 388 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Group.add">pygame.sprite.Group.add</a></td> | |
| 389 <td>—</td> | |
| 390 <td>add Sprites to this Group</td> | |
| 391 </tr> | |
| 392 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Group.remove">pygame.sprite.Group.remove</a></td> | |
| 393 <td>—</td> | |
| 394 <td>remove Sprites from the Group</td> | |
| 395 </tr> | |
| 396 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Group.has">pygame.sprite.Group.has</a></td> | |
| 397 <td>—</td> | |
| 398 <td>test if a Group contains Sprites</td> | |
| 399 </tr> | |
| 400 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Group.update">pygame.sprite.Group.update</a></td> | |
| 401 <td>—</td> | |
| 402 <td>call the update method on contained Sprites</td> | |
| 403 </tr> | |
| 404 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Group.draw">pygame.sprite.Group.draw</a></td> | |
| 405 <td>—</td> | |
| 406 <td>blit the Sprite images</td> | |
| 407 </tr> | |
| 408 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Group.clear">pygame.sprite.Group.clear</a></td> | |
| 409 <td>—</td> | |
| 410 <td>draw a background over the Sprites</td> | |
| 411 </tr> | |
| 412 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.Group.empty">pygame.sprite.Group.empty</a></td> | |
| 413 <td>—</td> | |
| 414 <td>remove all Sprites</td> | |
| 415 </tr> | |
| 416 </tbody> | |
| 417 </table> | |
| 418 <p>A simple container for Sprite objects. This class can be inherited to create | |
| 419 containers with more specific behaviors. The constructor takes any number of | |
| 420 Sprite arguments to add to the Group. The group supports the following | |
| 421 standard Python operations:</p> | |
| 422 <div class="highlight-python"><pre>in test if a Sprite is contained | |
| 423 len the number of Sprites contained | |
| 424 bool test if any Sprites are contained | |
| 425 iter iterate through all the Sprites</pre> | |
| 426 </div> | |
| 427 <p>The Sprites in the Group are not ordered, so drawing and iterating the | |
| 428 Sprites is in no particular order.</p> | |
| 429 <dl class="definition method"> | |
| 430 <dt class="title" id="pygame.sprite.Group.sprites"> | |
| 431 <tt class="descname">sprites</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Group.sprites" title="Permalink to this definition">¶</a></dt> | |
| 432 <dd><div class="line-block"> | |
| 433 <div class="line"><span class="summaryline">list of the Sprites this Group contains</span></div> | |
| 434 <div class="line"><span class="signature">sprites() -> sprite_list</span></div> | |
| 435 </div> | |
| 436 <p>Return a list of all the Sprites this group contains. You can also get an | |
| 437 iterator from the group, but you cannot iterator over a Group while | |
| 438 modifying it.</p> | |
| 439 </dd></dl> | |
| 440 | |
| 441 <dl class="definition method"> | |
| 442 <dt class="title" id="pygame.sprite.Group.copy"> | |
| 443 <tt class="descname">copy</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Group.copy" title="Permalink to this definition">¶</a></dt> | |
| 444 <dd><div class="line-block"> | |
| 445 <div class="line"><span class="summaryline">duplicate the Group</span></div> | |
| 446 <div class="line"><span class="signature">copy() -> Group</span></div> | |
| 447 </div> | |
| 448 <p>Creates a new Group with all the same Sprites as the original. If you | |
| 449 have subclassed Group, the new object will have the same (sub-)class as | |
| 450 the original. This only works if the derived class’s constructor takes | |
| 451 the same arguments as the Group class’s.</p> | |
| 452 </dd></dl> | |
| 453 | |
| 454 <dl class="definition method"> | |
| 455 <dt class="title" id="pygame.sprite.Group.add"> | |
| 456 <tt class="descname">add</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Group.add" title="Permalink to this definition">¶</a></dt> | |
| 457 <dd><div class="line-block"> | |
| 458 <div class="line"><span class="summaryline">add Sprites to this Group</span></div> | |
| 459 <div class="line"><span class="signature">add(*sprites) -> None</span></div> | |
| 460 </div> | |
| 461 <p>Add any number of Sprites to this Group. This will only add Sprites that | |
| 462 are not already members of the Group.</p> | |
| 463 <p>Each sprite argument can also be a iterator containing Sprites.</p> | |
| 464 </dd></dl> | |
| 465 | |
| 466 <dl class="definition method"> | |
| 467 <dt class="title" id="pygame.sprite.Group.remove"> | |
| 468 <tt class="descname">remove</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Group.remove" title="Permalink to this definition">¶</a></dt> | |
| 469 <dd><div class="line-block"> | |
| 470 <div class="line"><span class="summaryline">remove Sprites from the Group</span></div> | |
| 471 <div class="line"><span class="signature">remove(*sprites) -> None</span></div> | |
| 472 </div> | |
| 473 <p>Remove any number of Sprites from the Group. This will only remove | |
| 474 Sprites that are already members of the Group.</p> | |
| 475 <p>Each sprite argument can also be a iterator containing Sprites.</p> | |
| 476 </dd></dl> | |
| 477 | |
| 478 <dl class="definition method"> | |
| 479 <dt class="title" id="pygame.sprite.Group.has"> | |
| 480 <tt class="descname">has</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Group.has" title="Permalink to this definition">¶</a></dt> | |
| 481 <dd><div class="line-block"> | |
| 482 <div class="line"><span class="summaryline">test if a Group contains Sprites</span></div> | |
| 483 <div class="line"><span class="signature">has(*sprites) -> None</span></div> | |
| 484 </div> | |
| 485 <p>Return True if the Group contains all of the given sprites. This is | |
| 486 similar to using the “in” operator on the Group (“if sprite in group: | |
| 487 ...”), which tests if a single Sprite belongs to a Group.</p> | |
| 488 <p>Each sprite argument can also be a iterator containing Sprites.</p> | |
| 489 </dd></dl> | |
| 490 | |
| 491 <dl class="definition method"> | |
| 492 <dt class="title" id="pygame.sprite.Group.update"> | |
| 493 <tt class="descname">update</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Group.update" title="Permalink to this definition">¶</a></dt> | |
| 494 <dd><div class="line-block"> | |
| 495 <div class="line"><span class="summaryline">call the update method on contained Sprites</span></div> | |
| 496 <div class="line"><span class="signature">update(*args) -> None</span></div> | |
| 497 </div> | |
| 498 <p>Calls the <tt class="docutils literal"><span class="pre">update()</span></tt> method on all Sprites in the Group. The base | |
| 499 Sprite class has an update method that takes any number of arguments and | |
| 500 does nothing. The arguments passed to <tt class="docutils literal"><span class="pre">Group.update()</span></tt> will be passed | |
| 501 to each Sprite.</p> | |
| 502 <p>There is no way to get the return value from the <tt class="docutils literal"><span class="pre">Sprite.update()</span></tt> | |
| 503 methods.</p> | |
| 504 </dd></dl> | |
| 505 | |
| 506 <dl class="definition method"> | |
| 507 <dt class="title" id="pygame.sprite.Group.draw"> | |
| 508 <tt class="descname">draw</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Group.draw" title="Permalink to this definition">¶</a></dt> | |
| 509 <dd><div class="line-block"> | |
| 510 <div class="line"><span class="summaryline">blit the Sprite images</span></div> | |
| 511 <div class="line"><span class="signature">draw(Surface) -> None</span></div> | |
| 512 </div> | |
| 513 <p>Draws the contained Sprites to the Surface argument. This uses the | |
| 514 <tt class="docutils literal"><span class="pre">Sprite.image</span></tt> attribute for the source surface, and <tt class="docutils literal"><span class="pre">Sprite.rect</span></tt> | |
| 515 for the position.</p> | |
| 516 <p>The Group does not keep sprites in any order, so the draw order is | |
| 517 arbitrary.</p> | |
| 518 </dd></dl> | |
| 519 | |
| 520 <dl class="definition method"> | |
| 521 <dt class="title" id="pygame.sprite.Group.clear"> | |
| 522 <tt class="descname">clear</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Group.clear" title="Permalink to this definition">¶</a></dt> | |
| 523 <dd><div class="line-block"> | |
| 524 <div class="line"><span class="summaryline">draw a background over the Sprites</span></div> | |
| 525 <div class="line"><span class="signature">clear(Surface_dest, background) -> None</span></div> | |
| 526 </div> | |
| 527 <p>Erases the Sprites used in the last <tt class="docutils literal"><span class="pre">Group.draw()</span></tt> call. The | |
| 528 destination Surface is cleared by filling the drawn Sprite positions with | |
| 529 the background.</p> | |
| 530 <p>The background is usually a Surface image the same dimensions as the | |
| 531 destination Surface. However, it can also be a callback function that | |
| 532 takes two arguments; the destination Surface and an area to clear. The | |
| 533 background callback function will be called several times each clear.</p> | |
| 534 <p>Here is an example callback that will clear the Sprites with solid red:</p> | |
| 535 <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">clear_callback</span><span class="p">(</span><span class="n">surf</span><span class="p">,</span> <span class="n">rect</span><span class="p">):</span> | |
| 536 <span class="n">color</span> <span class="o">=</span> <span class="mi">255</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span> | |
| 537 <span class="n">surf</span><span class="o">.</span><span class="n">fill</span><span class="p">(</span><span class="n">color</span><span class="p">,</span> <span class="n">rect</span><span class="p">)</span> | |
| 538 </pre></div> | |
| 539 </div> | |
| 540 </dd></dl> | |
| 541 | |
| 542 <dl class="definition method"> | |
| 543 <dt class="title" id="pygame.sprite.Group.empty"> | |
| 544 <tt class="descname">empty</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.Group.empty" title="Permalink to this definition">¶</a></dt> | |
| 545 <dd><div class="line-block"> | |
| 546 <div class="line"><span class="summaryline">remove all Sprites</span></div> | |
| 547 <div class="line"><span class="signature">empty() -> None</span></div> | |
| 548 </div> | |
| 549 <p>Removes all Sprites from this Group.</p> | |
| 550 </dd></dl> | |
| 551 | |
| 552 </dd></dl> | |
| 553 | |
| 554 <dl class="definition class"> | |
| 555 <dt class="title" id="pygame.sprite.RenderPlain"> | |
| 556 <em class="property">class </em><tt class="descclassname">pygame.sprite.</tt><tt class="descname">RenderPlain</tt><a class="headerlink" href="#pygame.sprite.RenderPlain" title="Permalink to this definition">¶</a></dt> | |
| 557 <dd><p>same as pygame.sprite.Group</p> | |
| 558 </dd></dl> | |
| 559 | |
| 560 <dl class="definition class"> | |
| 561 <dt class="title" id="pygame.sprite.RenderClear"> | |
| 562 <em class="property">class </em><tt class="descclassname">pygame.sprite.</tt><tt class="descname">RenderClear</tt><a class="headerlink" href="#pygame.sprite.RenderClear" title="Permalink to this definition">¶</a></dt> | |
| 563 <dd><p>same as pygame.sprite.Group</p> | |
| 564 </dd></dl> | |
| 565 | |
| 566 <dl class="definition class"> | |
| 567 <dt class="title" id="pygame.sprite.RenderUpdates"> | |
| 568 <em class="property">class </em><tt class="descclassname">pygame.sprite.</tt><tt class="descname">RenderUpdates</tt><a class="headerlink" href="#pygame.sprite.RenderUpdates" title="Permalink to this definition">¶</a></dt> | |
| 569 <dd><div class="line-block"> | |
| 570 <div class="line"><span class="summaryline">Group class that tracks dirty updates</span></div> | |
| 571 <div class="line"><span class="signature">RenderUpdates(*sprites) -> RenderUpdates</span></div> | |
| 572 </div> | |
| 573 <table border="1" class="toc docutils"> | |
| 574 <colgroup> | |
| 575 <col width="37%" /> | |
| 576 <col width="1%" /> | |
| 577 <col width="62%" /> | |
| 578 </colgroup> | |
| 579 <tbody valign="top"> | |
| 580 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.RenderUpdates.draw">pygame.sprite.RenderUpdates.draw</a></td> | |
| 581 <td>—</td> | |
| 582 <td>blit the Sprite images and track changed areas</td> | |
| 583 </tr> | |
| 584 </tbody> | |
| 585 </table> | |
| 586 <p>This class is derived from <tt class="docutils literal"><span class="pre">pygame.sprite.Group()</span></tt>. It has an extended | |
| 587 <tt class="docutils literal"><span class="pre">draw()</span></tt> method that tracks the changed areas of the screen.</p> | |
| 588 <dl class="definition method"> | |
| 589 <dt class="title" id="pygame.sprite.RenderUpdates.draw"> | |
| 590 <tt class="descname">draw</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.RenderUpdates.draw" title="Permalink to this definition">¶</a></dt> | |
| 591 <dd><div class="line-block"> | |
| 592 <div class="line"><span class="summaryline">blit the Sprite images and track changed areas</span></div> | |
| 593 <div class="line"><span class="signature">draw(surface) -> Rect_list</span></div> | |
| 594 </div> | |
| 595 <p>Draws all the Sprites to the surface, the same as <tt class="docutils literal"><span class="pre">Group.draw()</span></tt>. This | |
| 596 method also returns a list of Rectangular areas on the screen that have | |
| 597 been changed. The returned changes include areas of the screen that have | |
| 598 been affected by previous <tt class="docutils literal"><span class="pre">Group.clear()</span></tt> calls.</p> | |
| 599 <p>The returned Rect list should be passed to <tt class="docutils literal"><span class="pre">pygame.display.update()</span></tt>. | |
| 600 This will help performance on software driven display modes. This type of | |
| 601 updating is usually only helpful on destinations with non-animating | |
| 602 backgrounds.</p> | |
| 603 </dd></dl> | |
| 604 | |
| 605 </dd></dl> | |
| 606 | |
| 607 <dl class="definition function"> | |
| 608 <dt class="title" id="pygame.sprite.OrderedUpdates"> | |
| 609 <tt class="descclassname">pygame.sprite.</tt><tt class="descname">OrderedUpdates</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.OrderedUpdates" title="Permalink to this definition">¶</a></dt> | |
| 610 <dd><div class="line-block"> | |
| 611 <div class="line"><span class="summaryline">RenderUpdates class that draws Sprites in order of addition</span></div> | |
| 612 <div class="line"><span class="signature">OrderedUpdates(*spites) -> OrderedUpdates</span></div> | |
| 613 </div> | |
| 614 <p>This class derives from <tt class="docutils literal"><span class="pre">pygame.sprite.RenderUpdates()</span></tt>. It maintains the | |
| 615 order in which the Sprites were added to the Group for rendering. This makes | |
| 616 adding and removing Sprites from the Group a little slower than regular | |
| 617 Groups.</p> | |
| 618 </dd></dl> | |
| 619 | |
| 620 <dl class="definition class"> | |
| 621 <dt class="title" id="pygame.sprite.LayeredUpdates"> | |
| 622 <em class="property">class </em><tt class="descclassname">pygame.sprite.</tt><tt class="descname">LayeredUpdates</tt><a class="headerlink" href="#pygame.sprite.LayeredUpdates" title="Permalink to this definition">¶</a></dt> | |
| 623 <dd><div class="line-block"> | |
| 624 <div class="line"><span class="summaryline">LayeredUpdates Group handles layers, that draws like OrderedUpdates.</span></div> | |
| 625 <div class="line"><span class="signature">LayeredUpdates(*spites, **kwargs) -> LayeredUpdates</span></div> | |
| 626 </div> | |
| 627 <table border="1" class="toc docutils"> | |
| 628 <colgroup> | |
| 629 <col width="42%" /> | |
| 630 <col width="1%" /> | |
| 631 <col width="58%" /> | |
| 632 </colgroup> | |
| 633 <tbody valign="top"> | |
| 634 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.add">pygame.sprite.LayeredUpdates.add</a></td> | |
| 635 <td>—</td> | |
| 636 <td>add a sprite or sequence of sprites to a group</td> | |
| 637 </tr> | |
| 638 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.sprites">pygame.sprite.LayeredUpdates.sprites</a></td> | |
| 639 <td>—</td> | |
| 640 <td>returns a ordered list of sprites (first back, last top).</td> | |
| 641 </tr> | |
| 642 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.draw">pygame.sprite.LayeredUpdates.draw</a></td> | |
| 643 <td>—</td> | |
| 644 <td>draw all sprites in the right order onto the passed surface.</td> | |
| 645 </tr> | |
| 646 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_sprites_at">pygame.sprite.LayeredUpdates.get_sprites_at</a></td> | |
| 647 <td>—</td> | |
| 648 <td>returns a list with all sprites at that position.</td> | |
| 649 </tr> | |
| 650 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_sprite">pygame.sprite.LayeredUpdates.get_sprite</a></td> | |
| 651 <td>—</td> | |
| 652 <td>returns the sprite at the index idx from the groups sprites</td> | |
| 653 </tr> | |
| 654 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.remove_sprites_of_layer">pygame.sprite.LayeredUpdates.remove_sprites_of_layer</a></td> | |
| 655 <td>—</td> | |
| 656 <td>removes all sprites from a layer and returns them as a list.</td> | |
| 657 </tr> | |
| 658 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.layers">pygame.sprite.LayeredUpdates.layers</a></td> | |
| 659 <td>—</td> | |
| 660 <td>returns a list of layers defined (unique), sorted from botton up.</td> | |
| 661 </tr> | |
| 662 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.change_layer">pygame.sprite.LayeredUpdates.change_layer</a></td> | |
| 663 <td>—</td> | |
| 664 <td>changes the layer of the sprite</td> | |
| 665 </tr> | |
| 666 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_layer_of_sprite">pygame.sprite.LayeredUpdates.get_layer_of_sprite</a></td> | |
| 667 <td>—</td> | |
| 668 <td>returns the layer that sprite is currently in.</td> | |
| 669 </tr> | |
| 670 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_top_layer">pygame.sprite.LayeredUpdates.get_top_layer</a></td> | |
| 671 <td>—</td> | |
| 672 <td>returns the top layer</td> | |
| 673 </tr> | |
| 674 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_bottom_layer">pygame.sprite.LayeredUpdates.get_bottom_layer</a></td> | |
| 675 <td>—</td> | |
| 676 <td>returns the bottom layer</td> | |
| 677 </tr> | |
| 678 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.move_to_front">pygame.sprite.LayeredUpdates.move_to_front</a></td> | |
| 679 <td>—</td> | |
| 680 <td>brings the sprite to front layer</td> | |
| 681 </tr> | |
| 682 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.move_to_back">pygame.sprite.LayeredUpdates.move_to_back</a></td> | |
| 683 <td>—</td> | |
| 684 <td>moves the sprite to the bottom layer</td> | |
| 685 </tr> | |
| 686 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_top_sprite">pygame.sprite.LayeredUpdates.get_top_sprite</a></td> | |
| 687 <td>—</td> | |
| 688 <td>returns the topmost sprite</td> | |
| 689 </tr> | |
| 690 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_sprites_from_layer">pygame.sprite.LayeredUpdates.get_sprites_from_layer</a></td> | |
| 691 <td>—</td> | |
| 692 <td>returns all sprites from a layer, ordered by how they where added</td> | |
| 693 </tr> | |
| 694 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.switch_layer">pygame.sprite.LayeredUpdates.switch_layer</a></td> | |
| 695 <td>—</td> | |
| 696 <td>switches the sprites from layer1 to layer2</td> | |
| 697 </tr> | |
| 698 </tbody> | |
| 699 </table> | |
| 700 <p>This group is fully compatible with <a class="tooltip reference internal" href="#pygame.sprite.Sprite" title=""><tt class="xref py py-class docutils literal"><span class="pre">pygame.sprite.Sprite</span></tt><span class="tooltip-content">simple base class for visible game objects</span></a>.</p> | |
| 701 <p>You can set the default layer through kwargs using ‘default_layer’ and an | |
| 702 integer for the layer. The default layer is 0.</p> | |
| 703 <p>If the sprite you add has an attribute layer then that layer will be used. | |
| 704 If the **kwarg contains ‘layer’ then the sprites passed will be added to | |
| 705 that layer (overriding the <tt class="docutils literal"><span class="pre">sprite.layer</span></tt> attribute). If neither sprite | |
| 706 has attribute layer nor **kwarg then the default layer is used to add the | |
| 707 sprites.</p> | |
| 708 <p>New in pygame 1.8.0</p> | |
| 709 <dl class="definition method"> | |
| 710 <dt class="title" id="pygame.sprite.LayeredUpdates.add"> | |
| 711 <tt class="descname">add</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.add" title="Permalink to this definition">¶</a></dt> | |
| 712 <dd><div class="line-block"> | |
| 713 <div class="line"><span class="summaryline">add a sprite or sequence of sprites to a group</span></div> | |
| 714 <div class="line"><span class="signature">add(*sprites, **kwargs) -> None</span></div> | |
| 715 </div> | |
| 716 <p>If the <tt class="docutils literal"><span class="pre">sprite(s)</span></tt> have an attribute layer then that is used for the | |
| 717 layer. If **kwargs contains ‘layer’ then the <tt class="docutils literal"><span class="pre">sprite(s)</span></tt> will be added | |
| 718 to that argument (overriding the sprite layer attribute). If neither is | |
| 719 passed then the <tt class="docutils literal"><span class="pre">sprite(s)</span></tt> will be added to the default layer.</p> | |
| 720 </dd></dl> | |
| 721 | |
| 722 <dl class="definition method"> | |
| 723 <dt class="title" id="pygame.sprite.LayeredUpdates.sprites"> | |
| 724 <tt class="descname">sprites</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.sprites" title="Permalink to this definition">¶</a></dt> | |
| 725 <dd><div class="line-block"> | |
| 726 <div class="line"><span class="summaryline">returns a ordered list of sprites (first back, last top).</span></div> | |
| 727 <div class="line"><span class="signature">sprites() -> sprites</span></div> | |
| 728 </div> | |
| 729 </dd></dl> | |
| 730 | |
| 731 <dl class="definition method"> | |
| 732 <dt class="title" id="pygame.sprite.LayeredUpdates.draw"> | |
| 733 <tt class="descname">draw</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.draw" title="Permalink to this definition">¶</a></dt> | |
| 734 <dd><div class="line-block"> | |
| 735 <div class="line"><span class="summaryline">draw all sprites in the right order onto the passed surface.</span></div> | |
| 736 <div class="line"><span class="signature">draw(surface) -> Rect_list</span></div> | |
| 737 </div> | |
| 738 </dd></dl> | |
| 739 | |
| 740 <dl class="definition method"> | |
| 741 <dt class="title" id="pygame.sprite.LayeredUpdates.get_sprites_at"> | |
| 742 <tt class="descname">get_sprites_at</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_sprites_at" title="Permalink to this definition">¶</a></dt> | |
| 743 <dd><div class="line-block"> | |
| 744 <div class="line"><span class="summaryline">returns a list with all sprites at that position.</span></div> | |
| 745 <div class="line"><span class="signature">get_sprites_at(pos) -> colliding_sprites</span></div> | |
| 746 </div> | |
| 747 <p>Bottom sprites first, top last.</p> | |
| 748 </dd></dl> | |
| 749 | |
| 750 <dl class="definition method"> | |
| 751 <dt class="title" id="pygame.sprite.LayeredUpdates.get_sprite"> | |
| 752 <tt class="descname">get_sprite</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_sprite" title="Permalink to this definition">¶</a></dt> | |
| 753 <dd><div class="line-block"> | |
| 754 <div class="line"><span class="summaryline">returns the sprite at the index idx from the groups sprites</span></div> | |
| 755 <div class="line"><span class="signature">get_sprite(idx) -> sprite</span></div> | |
| 756 </div> | |
| 757 <p>Raises IndexOutOfBounds if the idx is not within range.</p> | |
| 758 </dd></dl> | |
| 759 | |
| 760 <dl class="definition method"> | |
| 761 <dt class="title" id="pygame.sprite.LayeredUpdates.remove_sprites_of_layer"> | |
| 762 <tt class="descname">remove_sprites_of_layer</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.remove_sprites_of_layer" title="Permalink to this definition">¶</a></dt> | |
| 763 <dd><div class="line-block"> | |
| 764 <div class="line"><span class="summaryline">removes all sprites from a layer and returns them as a list.</span></div> | |
| 765 <div class="line"><span class="signature">remove_sprites_of_layer(layer_nr) -> sprites</span></div> | |
| 766 </div> | |
| 767 </dd></dl> | |
| 768 | |
| 769 <dl class="definition method"> | |
| 770 <dt class="title" id="pygame.sprite.LayeredUpdates.layers"> | |
| 771 <tt class="descname">layers</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.layers" title="Permalink to this definition">¶</a></dt> | |
| 772 <dd><div class="line-block"> | |
| 773 <div class="line"><span class="summaryline">returns a list of layers defined (unique), sorted from botton up.</span></div> | |
| 774 <div class="line"><span class="signature">layers() -> layers</span></div> | |
| 775 </div> | |
| 776 </dd></dl> | |
| 777 | |
| 778 <dl class="definition method"> | |
| 779 <dt class="title" id="pygame.sprite.LayeredUpdates.change_layer"> | |
| 780 <tt class="descname">change_layer</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.change_layer" title="Permalink to this definition">¶</a></dt> | |
| 781 <dd><div class="line-block"> | |
| 782 <div class="line"><span class="summaryline">changes the layer of the sprite</span></div> | |
| 783 <div class="line"><span class="signature">change_layer(sprite, new_layer) -> None</span></div> | |
| 784 </div> | |
| 785 <p>sprite must have been added to the renderer. It is not checked.</p> | |
| 786 </dd></dl> | |
| 787 | |
| 788 <dl class="definition method"> | |
| 789 <dt class="title" id="pygame.sprite.LayeredUpdates.get_layer_of_sprite"> | |
| 790 <tt class="descname">get_layer_of_sprite</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_layer_of_sprite" title="Permalink to this definition">¶</a></dt> | |
| 791 <dd><div class="line-block"> | |
| 792 <div class="line"><span class="summaryline">returns the layer that sprite is currently in.</span></div> | |
| 793 <div class="line"><span class="signature">get_layer_of_sprite(sprite) -> layer</span></div> | |
| 794 </div> | |
| 795 <p>If the sprite is not found then it will return the default layer.</p> | |
| 796 </dd></dl> | |
| 797 | |
| 798 <dl class="definition method"> | |
| 799 <dt class="title" id="pygame.sprite.LayeredUpdates.get_top_layer"> | |
| 800 <tt class="descname">get_top_layer</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_top_layer" title="Permalink to this definition">¶</a></dt> | |
| 801 <dd><div class="line-block"> | |
| 802 <div class="line"><span class="summaryline">returns the top layer</span></div> | |
| 803 <div class="line"><span class="signature">get_top_layer() -> layer</span></div> | |
| 804 </div> | |
| 805 </dd></dl> | |
| 806 | |
| 807 <dl class="definition method"> | |
| 808 <dt class="title" id="pygame.sprite.LayeredUpdates.get_bottom_layer"> | |
| 809 <tt class="descname">get_bottom_layer</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_bottom_layer" title="Permalink to this definition">¶</a></dt> | |
| 810 <dd><div class="line-block"> | |
| 811 <div class="line"><span class="summaryline">returns the bottom layer</span></div> | |
| 812 <div class="line"><span class="signature">get_bottom_layer() -> layer</span></div> | |
| 813 </div> | |
| 814 </dd></dl> | |
| 815 | |
| 816 <dl class="definition method"> | |
| 817 <dt class="title" id="pygame.sprite.LayeredUpdates.move_to_front"> | |
| 818 <tt class="descname">move_to_front</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.move_to_front" title="Permalink to this definition">¶</a></dt> | |
| 819 <dd><div class="line-block"> | |
| 820 <div class="line"><span class="summaryline">brings the sprite to front layer</span></div> | |
| 821 <div class="line"><span class="signature">move_to_front(sprite) -> None</span></div> | |
| 822 </div> | |
| 823 <p>Brings the sprite to front, changing sprite layer to topmost layer (added | |
| 824 at the end of that layer).</p> | |
| 825 </dd></dl> | |
| 826 | |
| 827 <dl class="definition method"> | |
| 828 <dt class="title" id="pygame.sprite.LayeredUpdates.move_to_back"> | |
| 829 <tt class="descname">move_to_back</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.move_to_back" title="Permalink to this definition">¶</a></dt> | |
| 830 <dd><div class="line-block"> | |
| 831 <div class="line"><span class="summaryline">moves the sprite to the bottom layer</span></div> | |
| 832 <div class="line"><span class="signature">move_to_back(sprite) -> None</span></div> | |
| 833 </div> | |
| 834 <p>Moves the sprite to the bottom layer, moving it behind all other layers | |
| 835 and adding one additional layer.</p> | |
| 836 </dd></dl> | |
| 837 | |
| 838 <dl class="definition method"> | |
| 839 <dt class="title" id="pygame.sprite.LayeredUpdates.get_top_sprite"> | |
| 840 <tt class="descname">get_top_sprite</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_top_sprite" title="Permalink to this definition">¶</a></dt> | |
| 841 <dd><div class="line-block"> | |
| 842 <div class="line"><span class="summaryline">returns the topmost sprite</span></div> | |
| 843 <div class="line"><span class="signature">get_top_sprite() -> Sprite</span></div> | |
| 844 </div> | |
| 845 </dd></dl> | |
| 846 | |
| 847 <dl class="definition method"> | |
| 848 <dt class="title" id="pygame.sprite.LayeredUpdates.get_sprites_from_layer"> | |
| 849 <tt class="descname">get_sprites_from_layer</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_sprites_from_layer" title="Permalink to this definition">¶</a></dt> | |
| 850 <dd><div class="line-block"> | |
| 851 <div class="line"><span class="summaryline">returns all sprites from a layer, ordered by how they where added</span></div> | |
| 852 <div class="line"><span class="signature">get_sprites_from_layer(layer) -> sprites</span></div> | |
| 853 </div> | |
| 854 <p>Returns all sprites from a layer, ordered by how they where added. It | |
| 855 uses linear search and the sprites are not removed from layer.</p> | |
| 856 </dd></dl> | |
| 857 | |
| 858 <dl class="definition method"> | |
| 859 <dt class="title" id="pygame.sprite.LayeredUpdates.switch_layer"> | |
| 860 <tt class="descname">switch_layer</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredUpdates.switch_layer" title="Permalink to this definition">¶</a></dt> | |
| 861 <dd><div class="line-block"> | |
| 862 <div class="line"><span class="summaryline">switches the sprites from layer1 to layer2</span></div> | |
| 863 <div class="line"><span class="signature">switch_layer(layer1_nr, layer2_nr) -> None</span></div> | |
| 864 </div> | |
| 865 <p>The layers number must exist, it is not checked.</p> | |
| 866 </dd></dl> | |
| 867 | |
| 868 </dd></dl> | |
| 869 | |
| 870 <dl class="definition class"> | |
| 871 <dt class="title" id="pygame.sprite.LayeredDirty"> | |
| 872 <em class="property">class </em><tt class="descclassname">pygame.sprite.</tt><tt class="descname">LayeredDirty</tt><a class="headerlink" href="#pygame.sprite.LayeredDirty" title="Permalink to this definition">¶</a></dt> | |
| 873 <dd><div class="line-block"> | |
| 874 <div class="line"><span class="summaryline">LayeredDirty Group is for DirtySprites. Subclasses LayeredUpdates.</span></div> | |
| 875 <div class="line"><span class="signature">LayeredDirty(*spites, **kwargs) -> LayeredDirty</span></div> | |
| 876 </div> | |
| 877 <table border="1" class="toc docutils"> | |
| 878 <colgroup> | |
| 879 <col width="37%" /> | |
| 880 <col width="1%" /> | |
| 881 <col width="62%" /> | |
| 882 </colgroup> | |
| 883 <tbody valign="top"> | |
| 884 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.draw">pygame.sprite.LayeredDirty.draw</a></td> | |
| 885 <td>—</td> | |
| 886 <td>draw all sprites in the right order onto the passed surface.</td> | |
| 887 </tr> | |
| 888 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.clear">pygame.sprite.LayeredDirty.clear</a></td> | |
| 889 <td>—</td> | |
| 890 <td>used to set background</td> | |
| 891 </tr> | |
| 892 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.repaint_rect">pygame.sprite.LayeredDirty.repaint_rect</a></td> | |
| 893 <td>—</td> | |
| 894 <td>repaints the given area</td> | |
| 895 </tr> | |
| 896 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.set_clip">pygame.sprite.LayeredDirty.set_clip</a></td> | |
| 897 <td>—</td> | |
| 898 <td>clip the area where to draw. Just pass None (default) to reset the clip</td> | |
| 899 </tr> | |
| 900 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.get_clip">pygame.sprite.LayeredDirty.get_clip</a></td> | |
| 901 <td>—</td> | |
| 902 <td>get the area where drawing will occur</td> | |
| 903 </tr> | |
| 904 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.change_layer">pygame.sprite.LayeredDirty.change_layer</a></td> | |
| 905 <td>—</td> | |
| 906 <td>changes the layer of the sprite</td> | |
| 907 </tr> | |
| 908 <tr><td><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.set_timing_treshold">pygame.sprite.LayeredDirty.set_timing_treshold</a></td> | |
| 909 <td>—</td> | |
| 910 <td>sets the treshold in milliseconds</td> | |
| 911 </tr> | |
| 912 </tbody> | |
| 913 </table> | |
| 914 <p>This group requires <a class="tooltip reference internal" href="#pygame.sprite.DirtySprite" title=""><tt class="xref py py-class docutils literal"><span class="pre">pygame.sprite.DirtySprite</span></tt><span class="tooltip-content">a more featureful subclass of Sprite with more attributes</span></a> or any sprite that | |
| 915 has the following attributes:</p> | |
| 916 <div class="highlight-python"><pre>image, rect, dirty, visible, blendmode (see doc of DirtySprite).</pre> | |
| 917 </div> | |
| 918 <p>It uses the dirty flag technique and is therefore faster than the | |
| 919 <a class="tooltip reference internal" href="#pygame.sprite.RenderUpdates" title=""><tt class="xref py py-class docutils literal"><span class="pre">pygame.sprite.RenderUpdates</span></tt><span class="tooltip-content">Group class that tracks dirty updates</span></a> if you have many static sprites. It | |
| 920 also switches automatically between dirty rect update and full screen | |
| 921 drawing, so you do no have to worry what would be faster.</p> | |
| 922 <p>Same as for the <a class="tooltip reference internal" href="#pygame.sprite.Group" title=""><tt class="xref py py-class docutils literal"><span class="pre">pygame.sprite.Group</span></tt><span class="tooltip-content">container class for many Sprites</span></a>. You can specify some | |
| 923 additional attributes through kwargs:</p> | |
| 924 <div class="highlight-python"><pre>_use_update: True/False default is False | |
| 925 _default_layer: default layer where sprites without a layer are added. | |
| 926 _time_threshold: treshold time for switching between dirty rect mode | |
| 927 and fullscreen mode, defaults to 1000./80 == 1000./fps</pre> | |
| 928 </div> | |
| 929 <p>New in pygame 1.8.0</p> | |
| 930 <dl class="definition method"> | |
| 931 <dt class="title" id="pygame.sprite.LayeredDirty.draw"> | |
| 932 <tt class="descname">draw</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredDirty.draw" title="Permalink to this definition">¶</a></dt> | |
| 933 <dd><div class="line-block"> | |
| 934 <div class="line"><span class="summaryline">draw all sprites in the right order onto the passed surface.</span></div> | |
| 935 <div class="line"><span class="signature">draw(surface, bgd=None) -> Rect_list</span></div> | |
| 936 </div> | |
| 937 <p>You can pass the background too. If a background is already set, then the | |
| 938 bgd argument has no effect.</p> | |
| 939 </dd></dl> | |
| 940 | |
| 941 <dl class="definition method"> | |
| 942 <dt class="title" id="pygame.sprite.LayeredDirty.clear"> | |
| 943 <tt class="descname">clear</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredDirty.clear" title="Permalink to this definition">¶</a></dt> | |
| 944 <dd><div class="line-block"> | |
| 945 <div class="line"><span class="summaryline">used to set background</span></div> | |
| 946 <div class="line"><span class="signature">clear(surface, bgd) -> None</span></div> | |
| 947 </div> | |
| 948 </dd></dl> | |
| 949 | |
| 950 <dl class="definition method"> | |
| 951 <dt class="title" id="pygame.sprite.LayeredDirty.repaint_rect"> | |
| 952 <tt class="descname">repaint_rect</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredDirty.repaint_rect" title="Permalink to this definition">¶</a></dt> | |
| 953 <dd><div class="line-block"> | |
| 954 <div class="line"><span class="summaryline">repaints the given area</span></div> | |
| 955 <div class="line"><span class="signature">repaint_rect(screen_rect) -> None</span></div> | |
| 956 </div> | |
| 957 <p>screen_rect is in screencoordinates. This method does not do any drawing by itself; the area specified by the rect attributes will be redrawn when the draw method is called.</p> | |
| 958 </dd></dl> | |
| 959 | |
| 960 <dl class="definition method"> | |
| 961 <dt class="title" id="pygame.sprite.LayeredDirty.set_clip"> | |
| 962 <tt class="descname">set_clip</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredDirty.set_clip" title="Permalink to this definition">¶</a></dt> | |
| 963 <dd><div class="line-block"> | |
| 964 <div class="line"><span class="summaryline">clip the area where to draw. Just pass None (default) to reset the clip</span></div> | |
| 965 <div class="line"><span class="signature">set_clip(screen_rect=None) -> None</span></div> | |
| 966 </div> | |
| 967 </dd></dl> | |
| 968 | |
| 969 <dl class="definition method"> | |
| 970 <dt class="title" id="pygame.sprite.LayeredDirty.get_clip"> | |
| 971 <tt class="descname">get_clip</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredDirty.get_clip" title="Permalink to this definition">¶</a></dt> | |
| 972 <dd><div class="line-block"> | |
| 973 <div class="line"><span class="summaryline">get the area where drawing will occur</span></div> | |
| 974 <div class="line"><span class="signature">get_clip() -> Rect</span></div> | |
| 975 </div> | |
| 976 </dd></dl> | |
| 977 | |
| 978 <dl class="definition method"> | |
| 979 <dt class="title" id="pygame.sprite.LayeredDirty.change_layer"> | |
| 980 <tt class="descname">change_layer</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredDirty.change_layer" title="Permalink to this definition">¶</a></dt> | |
| 981 <dd><div class="line-block"> | |
| 982 <div class="line"><span class="summaryline">changes the layer of the sprite</span></div> | |
| 983 <div class="line"><span class="signature">change_layer(sprite, new_layer) -> None</span></div> | |
| 984 </div> | |
| 985 <p>sprite must have been added to the renderer. It is not checked.</p> | |
| 986 </dd></dl> | |
| 987 | |
| 988 <dl class="definition method"> | |
| 989 <dt class="title" id="pygame.sprite.LayeredDirty.set_timing_treshold"> | |
| 990 <tt class="descname">set_timing_treshold</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.LayeredDirty.set_timing_treshold" title="Permalink to this definition">¶</a></dt> | |
| 991 <dd><div class="line-block"> | |
| 992 <div class="line"><span class="summaryline">sets the treshold in milliseconds</span></div> | |
| 993 <div class="line"><span class="signature">set_timing_treshold(time_ms) -> None</span></div> | |
| 994 </div> | |
| 995 <p>Default is 1000./80 where 80 is the fps I want to switch to full screen | |
| 996 mode.</p> | |
| 997 </dd></dl> | |
| 998 | |
| 999 </dd></dl> | |
| 1000 | |
| 1001 <dl class="definition function"> | |
| 1002 <dt class="title" id="pygame.sprite.GroupSingle"> | |
| 1003 <tt class="descclassname">pygame.sprite.</tt><tt class="descname">GroupSingle</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.GroupSingle" title="Permalink to this definition">¶</a></dt> | |
| 1004 <dd><div class="line-block"> | |
| 1005 <div class="line"><span class="summaryline">Group container that holds a single Sprite</span></div> | |
| 1006 <div class="line"><span class="signature">GroupSingle(sprite=None) -> GroupSingle</span></div> | |
| 1007 </div> | |
| 1008 <p>The GroupSingle container only holds a single Sprite. When a new Sprite is | |
| 1009 added, the old one is removed.</p> | |
| 1010 <p>There is a special property, <tt class="docutils literal"><span class="pre">GroupSingle.sprite</span></tt>, that accesses the | |
| 1011 Sprite that this Group contains. It can be None when the Group is empty. The | |
| 1012 property can also be assigned to add a Sprite into the GroupSingle | |
| 1013 container.</p> | |
| 1014 </dd></dl> | |
| 1015 | |
| 1016 <dl class="definition function"> | |
| 1017 <dt class="title" id="pygame.sprite.spritecollide"> | |
| 1018 <tt class="descclassname">pygame.sprite.</tt><tt class="descname">spritecollide</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.spritecollide" title="Permalink to this definition">¶</a></dt> | |
| 1019 <dd><div class="line-block"> | |
| 1020 <div class="line"><span class="summaryline">find Sprites in a Group that intersect another Sprite</span></div> | |
| 1021 <div class="line"><span class="signature">spritecollide(sprite, group, dokill, collided = None) -> Sprite_list</span></div> | |
| 1022 </div> | |
| 1023 <p>Return a list containing all Sprites in a Group that intersect with another | |
| 1024 Sprite. Intersection is determined by comparing the <tt class="docutils literal"><span class="pre">Sprite.rect</span></tt> | |
| 1025 attribute of each Sprite.</p> | |
| 1026 <p>The dokill argument is a bool. If set to True, all Sprites that collide will | |
| 1027 be removed from the Group.</p> | |
| 1028 <p>The collided argument is a callback function used to calculate if two | |
| 1029 sprites are colliding. it should take two sprites as values, and return a | |
| 1030 bool value indicating if they are colliding. If collided is not passed, all | |
| 1031 sprites must have a “rect” value, which is a rectangle of the sprite area, | |
| 1032 which will be used to calculate the collision.</p> | |
| 1033 <p>collided callables:</p> | |
| 1034 <div class="highlight-python"><div class="highlight"><pre><span class="n">collide_rect</span><span class="p">,</span> <span class="n">collide_rect_ratio</span><span class="p">,</span> <span class="n">collide_circle</span><span class="p">,</span> | |
| 1035 <span class="n">collide_circle_ratio</span><span class="p">,</span> <span class="n">collide_mask</span> | |
| 1036 </pre></div> | |
| 1037 </div> | |
| 1038 </dd></dl> | |
| 1039 | |
| 1040 <dl class="definition function"> | |
| 1041 <dt class="title" id="pygame.sprite.collide_rect"> | |
| 1042 <tt class="descclassname">pygame.sprite.</tt><tt class="descname">collide_rect</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.collide_rect" title="Permalink to this definition">¶</a></dt> | |
| 1043 <dd><div class="line-block"> | |
| 1044 <div class="line"><span class="summaryline">collision detection between two sprites, using rects.</span></div> | |
| 1045 <div class="line"><span class="signature">collide_rect(left, right) -> bool</span></div> | |
| 1046 </div> | |
| 1047 <p>Tests for collision between two sprites. Uses the pygame rect colliderect | |
| 1048 function to calculate the collision. Intended to be passed as a collided | |
| 1049 callback function to the *collide functions. Sprites must have a “rect” | |
| 1050 attributes.</p> | |
| 1051 <p>New in pygame 1.8.0</p> | |
| 1052 </dd></dl> | |
| 1053 | |
| 1054 <dl class="definition function"> | |
| 1055 <dt class="title" id="pygame.sprite.collide_rect_ratio"> | |
| 1056 <tt class="descclassname">pygame.sprite.</tt><tt class="descname">collide_rect_ratio</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.collide_rect_ratio" title="Permalink to this definition">¶</a></dt> | |
| 1057 <dd><div class="line-block"> | |
| 1058 <div class="line"><span class="summaryline">collision detection between two sprites, using rects scaled to a ratio.</span></div> | |
| 1059 <div class="line"><span class="signature">collide_rect_ratio(ratio) -> collided_callable</span></div> | |
| 1060 </div> | |
| 1061 <p>A callable class that checks for collisions between two sprites, using a | |
| 1062 scaled version of the sprites rects.</p> | |
| 1063 <p>Is created with a ratio, the instance is then intended to be passed as a | |
| 1064 collided callback function to the *collide functions.</p> | |
| 1065 <p>A ratio is a floating point number - 1.0 is the same size, 2.0 is twice as | |
| 1066 big, and 0.5 is half the size.</p> | |
| 1067 <p>New in pygame 1.8.1</p> | |
| 1068 </dd></dl> | |
| 1069 | |
| 1070 <dl class="definition function"> | |
| 1071 <dt class="title" id="pygame.sprite.collide_circle"> | |
| 1072 <tt class="descclassname">pygame.sprite.</tt><tt class="descname">collide_circle</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.collide_circle" title="Permalink to this definition">¶</a></dt> | |
| 1073 <dd><div class="line-block"> | |
| 1074 <div class="line"><span class="summaryline">collision detection between two sprites, using circles.</span></div> | |
| 1075 <div class="line"><span class="signature">collide_circle(left, right) -> bool</span></div> | |
| 1076 </div> | |
| 1077 <p>Tests for collision between two sprites, by testing to see if two circles | |
| 1078 centered on the sprites overlap. If the sprites have a “radius” attribute, | |
| 1079 that is used to create the circle, otherwise a circle is created that is big | |
| 1080 enough to completely enclose the sprites rect as given by the “rect” | |
| 1081 attribute. Intended to be passed as a collided callback function to the | |
| 1082 *collide functions. Sprites must have a “rect” and an optional “radius” | |
| 1083 attribute.</p> | |
| 1084 <p>New in pygame 1.8.1</p> | |
| 1085 </dd></dl> | |
| 1086 | |
| 1087 <dl class="definition function"> | |
| 1088 <dt class="title" id="pygame.sprite.collide_circle_ratio"> | |
| 1089 <tt class="descclassname">pygame.sprite.</tt><tt class="descname">collide_circle_ratio</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.collide_circle_ratio" title="Permalink to this definition">¶</a></dt> | |
| 1090 <dd><div class="line-block"> | |
| 1091 <div class="line"><span class="summaryline">collision detection between two sprites, using circles scaled to a ratio.</span></div> | |
| 1092 <div class="line"><span class="signature">collide_circle_ratio(ratio) -> collided_callable</span></div> | |
| 1093 </div> | |
| 1094 <p>A callable class that checks for collisions between two sprites, using a | |
| 1095 scaled version of the sprites radius.</p> | |
| 1096 <p>Is created with a floating point ratio, the instance is then intended to be | |
| 1097 passed as a collided callback function to the *collide functions.</p> | |
| 1098 <p>A ratio is a floating point number - 1.0 is the same size, 2.0 is twice as | |
| 1099 big, and 0.5 is half the size.</p> | |
| 1100 <p>The created callable tests for collision between two sprites, by testing to | |
| 1101 see if two circles centered on the sprites overlap, after scaling the | |
| 1102 circles radius by the stored ratio. If the sprites have a “radius” | |
| 1103 attribute, that is used to create the circle, otherwise a circle is created | |
| 1104 that is big enough to completely enclose the sprites rect as given by the | |
| 1105 “rect” attribute. Intended to be passed as a collided callback function to | |
| 1106 the *collide functions. Sprites must have a “rect” and an optional “radius” | |
| 1107 attribute.</p> | |
| 1108 <p>New in pygame 1.8.1</p> | |
| 1109 </dd></dl> | |
| 1110 | |
| 1111 <dl class="definition function"> | |
| 1112 <dt class="title" id="pygame.sprite.collide_mask"> | |
| 1113 <tt class="descclassname">pygame.sprite.</tt><tt class="descname">collide_mask</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.collide_mask" title="Permalink to this definition">¶</a></dt> | |
| 1114 <dd><div class="line-block"> | |
| 1115 <div class="line"><span class="summaryline">collision detection between two sprites, using masks.</span></div> | |
| 1116 <div class="line"><span class="signature">collide_mask(SpriteLeft, SpriteRight) -> point</span></div> | |
| 1117 </div> | |
| 1118 <p>Returns first point on the mask where the masks collided, or None if | |
| 1119 there was no collision.</p> | |
| 1120 <p>Tests for collision between two sprites, by testing if thier bitmasks | |
| 1121 overlap. If the sprites have a “mask” attribute, that is used as the mask, | |
| 1122 otherwise a mask is created from the sprite image. Intended to be passed as | |
| 1123 a collided callback function to the *collide functions. Sprites must have a | |
| 1124 “rect” and an optional “mask” attribute.</p> | |
| 1125 <p>You should consider creating a mask for your sprite at load time if you | |
| 1126 are going to check collisions many times. This will increase the | |
| 1127 performance, otherwise this can be an expensive function because it | |
| 1128 will create the masks each time you check for collisions.</p> | |
| 1129 <div class="highlight-python"><div class="highlight"><pre><span class="n">sprite</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="n">pygame</span><span class="o">.</span><span class="n">mask</span><span class="o">.</span><span class="n">from_surface</span><span class="p">(</span><span class="n">sprite</span><span class="o">.</span><span class="n">image</span><span class="p">)</span> | |
| 1130 </pre></div> | |
| 1131 </div> | |
| 1132 <p>New in pygame 1.8.0</p> | |
| 1133 </dd></dl> | |
| 1134 | |
| 1135 <dl class="definition function"> | |
| 1136 <dt class="title" id="pygame.sprite.groupcollide"> | |
| 1137 <tt class="descclassname">pygame.sprite.</tt><tt class="descname">groupcollide</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.groupcollide" title="Permalink to this definition">¶</a></dt> | |
| 1138 <dd><div class="line-block"> | |
| 1139 <div class="line"><span class="summaryline">find all Sprites that collide between two Groups</span></div> | |
| 1140 <div class="line"><span class="signature">groupcollide(group1, group2, dokill1, dokill2, collided = None) -> Sprite_dict</span></div> | |
| 1141 </div> | |
| 1142 <p>This will find collisions between all the Sprites in two groups. | |
| 1143 Collision is determined by comparing the <tt class="docutils literal"><span class="pre">Sprite.rect</span></tt> attribute of | |
| 1144 each Sprite or by using the collided function if it is not None.</p> | |
| 1145 <p>Every Sprite inside group1 is added to the return dictionary. The value for | |
| 1146 each item is the list of Sprites in group2 that intersect.</p> | |
| 1147 <p>If either dokill argument is True, the colliding Sprites will be removed | |
| 1148 from their respective Group.</p> | |
| 1149 <p>The collided argument is a callback function used to calculate if two sprites are | |
| 1150 colliding. It should take two sprites as values and return a bool value | |
| 1151 indicating if they are colliding. If collided is not passed, then all | |
| 1152 sprites must have a “rect” value, which is a rectangle of the sprite area, | |
| 1153 which will be used to calculate the collision.</p> | |
| 1154 </dd></dl> | |
| 1155 | |
| 1156 <dl class="definition function"> | |
| 1157 <dt class="title" id="pygame.sprite.spritecollideany"> | |
| 1158 <tt class="descclassname">pygame.sprite.</tt><tt class="descname">spritecollideany</tt><big>(</big><big>)</big><a class="headerlink" href="#pygame.sprite.spritecollideany" title="Permalink to this definition">¶</a></dt> | |
| 1159 <dd><div class="line-block"> | |
| 1160 <div class="line"><span class="summaryline">simple test if a Sprite intersects anything in a Group</span></div> | |
| 1161 <div class="line"><span class="signature">spritecollideany(sprite, group, collided = None) -> Sprite</span> Collision with the returned sprite.</div> | |
| 1162 <div class="line"><span class="signature">spritecollideany(sprite, group, collided = None) -> None</span> No collision</div> | |
| 1163 </div> | |
| 1164 <p>If the sprite collides with any single sprite in the group, a single | |
| 1165 sprite from the group is returned. On no collision None is returned.</p> | |
| 1166 <p>If you don’t need all the features of the <tt class="docutils literal"><span class="pre">pygame.sprite.spritecollide()</span></tt> function, this | |
| 1167 function will be a bit quicker.</p> | |
| 1168 <p>The collided argument is a callback function used to calculate if two sprites are | |
| 1169 colliding. It should take two sprites as values and return a bool value | |
| 1170 indicating if they are colliding. If collided is not passed, then all | |
| 1171 sprites must have a “rect” value, which is a rectangle of the sprite area, | |
| 1172 which will be used to calculate the collision.</p> | |
| 1173 </dd></dl> | |
| 1174 | |
| 1175 </dd></dl> | |
| 1176 | |
| 1177 </div> | |
| 1178 | |
| 1179 </div> | |
| 1180 </div> | |
| 1181 </div> | |
| 1182 <div class="clearer"></div> | |
| 1183 </div> | |
| 1184 <div class="related"> | |
| 1185 <h3>Navigation</h3> | |
| 1186 <ul> | |
| 1187 <li class="right" style="margin-right: 10px"> | |
| 1188 <a href="../genindex.html" title="General Index" | |
| 1189 accesskey="I">index</a></li> | |
| 1190 <li class="right" > | |
| 1191 <a href="surface.html" title="pygame.Surface" | |
| 1192 accesskey="N">next</a> |</li> | |
| 1193 <li class="right" > | |
| 1194 <a href="sndarray.html" title="pygame.sndarray" | |
| 1195 accesskey="P">previous</a> |</li> | |
| 1196 <li><a href="../index.html">Pygame v1.9.2 documentation</a> »</li> | |
| 1197 <script type="text/javascript" src="jquery.plugin.docscomments.js"></script> | |
| 1198 | |
| 1199 </ul> | |
| 1200 </div> | |
| 1201 <div class="footer"> | |
| 1202 © Copyright 2011, Pygame Developers. | |
| 1203 </div> | |
| 1204 </body> | |
|
2198
da4302429d3b
replace makeref.py generated documents with makeref2.py documents
Lenard Lindstrom <len-l@telus.net>
parents:
2166
diff
changeset
|
1205 </html> |
