1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>pygame.sprite — pygame v2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/pygame.css" />
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<link rel="shortcut icon" href="../_static/pygame.ico"/>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="pygame.Surface" href="surface.html" />
<link rel="prev" title="pygame.sndarray" href="sndarray.html" />
</head><body>
<div class="document">
<div class="header">
<table>
<tr>
<td class="logo">
<a href="https://www.pygame.org/">
<img src="../_static/pygame_tiny.png"/>
</a>
<h5>pygame documentation</h5>
</td>
<td class="pagelinks">
<div class="top">
<a href="https://www.pygame.org/">Pygame Home</a> ||
<a href="../index.html">Help Contents</a> ||
<a href="../genindex.html">Reference Index</a>
<form action="../search.html" method="get" style="display:inline;float:right;">
<input name="q" value="" type="text">
<input value="search" type="submit">
</form>
</div>
<hr style="color:black;border-bottom:none;border-style: dotted;border-bottom-style:none;">
<p class="bottom"><b>Most useful stuff</b>:
<a href="color.html">Color</a> |
<a href="display.html">display</a> |
<a href="draw.html">draw</a> |
<a href="event.html">event</a> |
<a href="font.html">font</a> |
<a href="image.html">image</a> |
<a href="key.html">key</a> |
<a href="locals.html">locals</a> |
<a href="mixer.html">mixer</a> |
<a href="mouse.html">mouse</a> |
<a href="rect.html">Rect</a> |
<a href="surface.html">Surface</a> |
<a href="time.html">time</a> |
<a href="music.html">music</a> |
<a href="pygame.html">pygame</a>
</p>
<p class="bottom"><b>Advanced stuff</b>:
<a href="cursors.html">cursors</a> |
<a href="joystick.html">joystick</a> |
<a href="mask.html">mask</a> |
<a href="sprite.html">sprite</a> |
<a href="transform.html">transform</a> |
<a href="bufferproxy.html">BufferProxy</a> |
<a href="freetype.html">freetype</a> |
<a href="gfxdraw.html">gfxdraw</a> |
<a href="midi.html">midi</a> |
<a href="pixelarray.html">PixelArray</a> |
<a href="pixelcopy.html">pixelcopy</a> |
<a href="sndarray.html">sndarray</a> |
<a href="surfarray.html">surfarray</a> |
<a href="math.html">math</a>
</p>
<p class="bottom"><b>Other</b>:
<a href="camera.html">camera</a> |
<a href="sdl2_controller.html#module-pygame._sdl2.controller">controller</a> |
<a href="examples.html">examples</a> |
<a href="fastevent.html">fastevent</a> |
<a href="scrap.html">scrap</a> |
<a href="tests.html">tests</a> |
<a href="touch.html">touch</a> |
<a href="pygame.html#module-pygame.version">version</a>
</p>
</td>
</tr>
</table>
</div>
<div class="documentwrapper">
<div class="body" role="main">
<section id="module-pygame.sprite">
<span id="pygame-sprite"></span><dl class="definition">
<dt class="title module sig sig-object">
<code class="docutils literal notranslate"><span class="pre">pygame.sprite</span></code></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">pygame module with basic game object classes</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 28%" />
<col style="width: 1%" />
<col style="width: 72%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite">pygame.sprite.Sprite</a></div>
</td>
<td>—</td>
<td>Simple base class for visible game objects.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.DirtySprite">pygame.sprite.DirtySprite</a></div>
</td>
<td>—</td>
<td>A subclass of Sprite with more attributes and features.</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Group">pygame.sprite.Group</a></div>
</td>
<td>—</td>
<td>A container class to hold and manage multiple Sprite objects.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.RenderPlain">pygame.sprite.RenderPlain</a></div>
</td>
<td>—</td>
<td>Same as pygame.sprite.Group</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.RenderClear">pygame.sprite.RenderClear</a></div>
</td>
<td>—</td>
<td>Same as pygame.sprite.Group</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.RenderUpdates">pygame.sprite.RenderUpdates</a></div>
</td>
<td>—</td>
<td>Group sub-class that tracks dirty updates.</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.OrderedUpdates">pygame.sprite.OrderedUpdates</a></div>
</td>
<td>—</td>
<td>RenderUpdates sub-class that draws Sprites in order of addition.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates">pygame.sprite.LayeredUpdates</a></div>
</td>
<td>—</td>
<td>LayeredUpdates is a sprite group that handles layers and draws like OrderedUpdates.</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty">pygame.sprite.LayeredDirty</a></div>
</td>
<td>—</td>
<td>LayeredDirty group is for DirtySprite objects. Subclasses LayeredUpdates.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.GroupSingle">pygame.sprite.GroupSingle</a></div>
</td>
<td>—</td>
<td>Group container that holds a single sprite.</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.spritecollide">pygame.sprite.spritecollide</a></div>
</td>
<td>—</td>
<td>Find sprites in a group that intersect another sprite.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.collide_rect">pygame.sprite.collide_rect</a></div>
</td>
<td>—</td>
<td>Collision detection between two sprites, using rects.</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.collide_rect_ratio">pygame.sprite.collide_rect_ratio</a></div>
</td>
<td>—</td>
<td>Collision detection between two sprites, using rects scaled to a ratio.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.collide_circle">pygame.sprite.collide_circle</a></div>
</td>
<td>—</td>
<td>Collision detection between two sprites, using circles.</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.collide_circle_ratio">pygame.sprite.collide_circle_ratio</a></div>
</td>
<td>—</td>
<td>Collision detection between two sprites, using circles scaled to a ratio.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.collide_mask">pygame.sprite.collide_mask</a></div>
</td>
<td>—</td>
<td>Collision detection between two sprites, using masks.</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.groupcollide">pygame.sprite.groupcollide</a></div>
</td>
<td>—</td>
<td>Find all sprites that collide between two groups.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.spritecollideany">pygame.sprite.spritecollideany</a></div>
</td>
<td>—</td>
<td>Simple test if a sprite intersects anything in a group.</td>
</tr>
</tbody>
</table>
<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>
<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. A game could create new types of Group classes that operate on
specially customized Sprite instances they contain.</p>
<p>The basic Sprite class can draw the Sprites it contains to a Surface. The
<code class="docutils literal notranslate"><span class="pre">Group.draw()</span></code> method requires that each Sprite have a <code class="docutils literal notranslate"><span class="pre">Surface.image</span></code>
attribute and a <code class="docutils literal notranslate"><span class="pre">Surface.rect</span></code>. The <code class="docutils literal notranslate"><span class="pre">Group.clear()</span></code> method requires these
same attributes, and can be used to erase all the Sprites with background.
There are also more advanced Groups: <code class="docutils literal notranslate"><span class="pre">pygame.sprite.RenderUpdates()</span></code> and
<code class="docutils literal notranslate"><span class="pre">pygame.sprite.OrderedUpdates()</span></code>.</p>
<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 <code class="docutils literal notranslate"><span class="pre">Surface.rect</span></code>
attribute assigned.</p>
<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. A given Sprite can exist in any number of groups. A 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>
<p>Sprites and Groups manage their relationships with the <code class="docutils literal notranslate"><span class="pre">add()</span></code> and
<code class="docutils literal notranslate"><span class="pre">remove()</span></code> 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>
<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>
<p>Sprites are not thread safe. So lock them yourself if using threads.</p>
<dl class="py class definition">
<dt class="sig sig-object py title" id="pygame.sprite.Sprite">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">Sprite</span></span><a class="headerlink" href="#pygame.sprite.Sprite" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Simple base class for visible game objects.</span></div>
<div class="line"><span class="signature">Sprite(*groups) -> Sprite</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 37%" />
<col style="width: 1%" />
<col style="width: 62%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite.update">pygame.sprite.Sprite.update</a></div>
</td>
<td>—</td>
<td>method to control sprite behavior</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite.add">pygame.sprite.Sprite.add</a></div>
</td>
<td>—</td>
<td>add the sprite to groups</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite.remove">pygame.sprite.Sprite.remove</a></div>
</td>
<td>—</td>
<td>remove the sprite from groups</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite.kill">pygame.sprite.Sprite.kill</a></div>
</td>
<td>—</td>
<td>remove the Sprite from all Groups</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite.alive">pygame.sprite.Sprite.alive</a></div>
</td>
<td>—</td>
<td>does the sprite belong to any groups</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Sprite.groups">pygame.sprite.Sprite.groups</a></div>
</td>
<td>—</td>
<td>list of Groups that contain this Sprite</td>
</tr>
</tbody>
</table>
<p>The base class for visible game objects. Derived classes will want to
override the <code class="docutils literal notranslate"><span class="pre">Sprite.update()</span></code> and assign a <code class="docutils literal notranslate"><span class="pre">Sprite.image</span></code> and
<code class="docutils literal notranslate"><span class="pre">Sprite.rect</span></code> attributes. The initializer can accept any number of Group
instances to be added to.</p>
<p>When subclassing the Sprite, be sure to call the base initializer before
adding the Sprite to Groups. For example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">Block</span><span class="p">(</span><span class="n">pygame</span><span class="o">.</span><span class="n">sprite</span><span class="o">.</span><span class="n">Sprite</span><span class="p">):</span>
<span class="c1"># Constructor. Pass in the color of the block,</span>
<span class="c1"># and its x and y position</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">):</span>
<span class="c1"># Call the parent class (Sprite) constructor</span>
<span class="n">pygame</span><span class="o">.</span><span class="n">sprite</span><span class="o">.</span><span class="n">Sprite</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<span class="c1"># Create an image of the block, and fill it with a color.</span>
<span class="c1"># This could also be an image loaded from the disk.</span>
<span class="bp">self</span><span class="o">.</span><span class="n">image</span> <span class="o">=</span> <span class="n">pygame</span><span class="o">.</span><span class="n">Surface</span><span class="p">([</span><span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">image</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="c1"># Fetch the rectangle object that has the dimensions of the image</span>
<span class="c1"># Update the position of this object by setting the values of rect.x and rect.y</span>
<span class="bp">self</span><span class="o">.</span><span class="n">rect</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">image</span><span class="o">.</span><span class="n">get_rect</span><span class="p">()</span>
</pre></div>
</div>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Sprite.update">
<span class="sig-name descname"><span class="pre">update</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Sprite.update" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">method to control sprite behavior</span></div>
<div class="line"><span class="signature">update(*args, **kwargs) -> None</span></div>
</div>
<p>The default implementation of this method does nothing; it's just a
convenient "hook" that you can override. This method is called by
<code class="docutils literal notranslate"><span class="pre">Group.update()</span></code> with whatever arguments you give it.</p>
<p>There is no need to use this method if not using the convenience method
by the same name in the Group class.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Sprite.add">
<span class="sig-name descname"><span class="pre">add</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Sprite.add" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">add the sprite to groups</span></div>
<div class="line"><span class="signature">add(*groups) -> None</span></div>
</div>
<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>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Sprite.remove">
<span class="sig-name descname"><span class="pre">remove</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Sprite.remove" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">remove the sprite from groups</span></div>
<div class="line"><span class="signature">remove(*groups) -> None</span></div>
</div>
<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>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Sprite.kill">
<span class="sig-name descname"><span class="pre">kill</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Sprite.kill" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">remove the Sprite from all Groups</span></div>
<div class="line"><span class="signature">kill() -> None</span></div>
</div>
<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>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Sprite.alive">
<span class="sig-name descname"><span class="pre">alive</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Sprite.alive" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">does the sprite belong to any groups</span></div>
<div class="line"><span class="signature">alive() -> bool</span></div>
</div>
<p>Returns True when the Sprite belongs to one or more Groups.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Sprite.groups">
<span class="sig-name descname"><span class="pre">groups</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Sprite.groups" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">list of Groups that contain this Sprite</span></div>
<div class="line"><span class="signature">groups() -> group_list</span></div>
</div>
<p>Return a list of all the Groups that contain this Sprite.</p>
</dd></dl>
</dd></dl>
<dl class="py class definition">
<dt class="sig sig-object py title" id="pygame.sprite.DirtySprite">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">DirtySprite</span></span><a class="headerlink" href="#pygame.sprite.DirtySprite" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">A subclass of Sprite with more attributes and features.</span></div>
<div class="line"><span class="signature">DirtySprite(*groups) -> DirtySprite</span></div>
</div>
<p>Extra DirtySprite attributes with their default values:</p>
<p>dirty = 1</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="nb">set</span> <span class="n">to</span> <span class="mi">1</span><span class="p">,</span> <span class="n">it</span> <span class="ow">is</span> <span class="n">repainted</span> <span class="ow">and</span> <span class="n">then</span> <span class="nb">set</span> <span class="n">to</span> <span class="mi">0</span> <span class="n">again</span>
<span class="k">if</span> <span class="nb">set</span> <span class="n">to</span> <span class="mi">2</span> <span class="n">then</span> <span class="n">it</span> <span class="ow">is</span> <span class="n">always</span> <span class="n">dirty</span> <span class="p">(</span> <span class="n">repainted</span> <span class="n">each</span> <span class="n">frame</span><span class="p">,</span>
<span class="n">flag</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">reset</span><span class="p">)</span>
<span class="mi">0</span> <span class="n">means</span> <span class="n">that</span> <span class="n">it</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">dirty</span> <span class="ow">and</span> <span class="n">therefore</span> <span class="ow">not</span> <span class="n">repainted</span> <span class="n">again</span>
</pre></div>
</div>
<p>blendmode = 0</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">its</span> <span class="n">the</span> <span class="n">special_flags</span> <span class="n">argument</span> <span class="n">of</span> <span class="n">blit</span><span class="p">,</span> <span class="n">blendmodes</span>
</pre></div>
</div>
<p>source_rect = None</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">source</span> <span class="n">rect</span> <span class="n">to</span> <span class="n">use</span><span class="p">,</span> <span class="n">remember</span> <span class="n">that</span> <span class="n">it</span> <span class="ow">is</span> <span class="n">relative</span> <span class="n">to</span>
<span class="n">topleft</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span> <span class="n">of</span> <span class="bp">self</span><span class="o">.</span><span class="n">image</span>
</pre></div>
</div>
<p>visible = 1</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">normally</span> <span class="mi">1</span><span class="p">,</span> <span class="k">if</span> <span class="nb">set</span> <span class="n">to</span> <span class="mi">0</span> <span class="n">it</span> <span class="n">will</span> <span class="ow">not</span> <span class="n">be</span> <span class="n">repainted</span>
<span class="p">(</span><span class="n">you</span> <span class="n">must</span> <span class="nb">set</span> <span class="n">it</span> <span class="n">dirty</span> <span class="n">too</span> <span class="n">to</span> <span class="n">be</span> <span class="n">erased</span> <span class="kn">from</span> <span class="nn">screen</span><span class="p">)</span>
</pre></div>
</div>
<p>layer = 0</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">(</span><span class="n">READONLY</span> <span class="n">value</span><span class="p">,</span> <span class="n">it</span> <span class="ow">is</span> <span class="n">read</span> <span class="n">when</span> <span class="n">adding</span> <span class="n">it</span> <span class="n">to</span> <span class="n">the</span>
<span class="n">LayeredDirty</span><span class="p">,</span> <span class="k">for</span> <span class="n">details</span> <span class="n">see</span> <span class="n">doc</span> <span class="n">of</span> <span class="n">LayeredDirty</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<dl class="py class definition">
<dt class="sig sig-object py title" id="pygame.sprite.Group">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">Group</span></span><a class="headerlink" href="#pygame.sprite.Group" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">A container class to hold and manage multiple Sprite objects.</span></div>
<div class="line"><span class="signature">Group(*sprites) -> Group</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 35%" />
<col style="width: 1%" />
<col style="width: 64%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Group.sprites">pygame.sprite.Group.sprites</a></div>
</td>
<td>—</td>
<td>list of the Sprites this Group contains</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Group.copy">pygame.sprite.Group.copy</a></div>
</td>
<td>—</td>
<td>duplicate the Group</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Group.add">pygame.sprite.Group.add</a></div>
</td>
<td>—</td>
<td>add Sprites to this Group</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Group.remove">pygame.sprite.Group.remove</a></div>
</td>
<td>—</td>
<td>remove Sprites from the Group</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Group.has">pygame.sprite.Group.has</a></div>
</td>
<td>—</td>
<td>test if a Group contains Sprites</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Group.update">pygame.sprite.Group.update</a></div>
</td>
<td>—</td>
<td>call the update method on contained Sprites</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Group.draw">pygame.sprite.Group.draw</a></div>
</td>
<td>—</td>
<td>blit the Sprite images</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Group.clear">pygame.sprite.Group.clear</a></div>
</td>
<td>—</td>
<td>draw a background over the Sprites</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.Group.empty">pygame.sprite.Group.empty</a></div>
</td>
<td>—</td>
<td>remove all Sprites</td>
</tr>
</tbody>
</table>
<p>A 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>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ow">in</span> <span class="n">test</span> <span class="k">if</span> <span class="n">a</span> <span class="n">Sprite</span> <span class="ow">is</span> <span class="n">contained</span>
<span class="nb">len</span> <span class="n">the</span> <span class="n">number</span> <span class="n">of</span> <span class="n">Sprites</span> <span class="n">contained</span>
<span class="nb">bool</span> <span class="n">test</span> <span class="k">if</span> <span class="nb">any</span> <span class="n">Sprites</span> <span class="n">are</span> <span class="n">contained</span>
<span class="nb">iter</span> <span class="n">iterate</span> <span class="n">through</span> <span class="nb">all</span> <span class="n">the</span> <span class="n">Sprites</span>
</pre></div>
</div>
<p>The Sprites in the Group are ordered only on python 3.6 and higher.
Below python 3.6 drawing and iterating over the Sprites is in no particular order.</p>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Group.sprites">
<span class="sig-name descname"><span class="pre">sprites</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Group.sprites" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">list of the Sprites this Group contains</span></div>
<div class="line"><span class="signature">sprites() -> sprite_list</span></div>
</div>
<p>Return a list of all the Sprites this group contains. You can also get an
iterator from the group, but you cannot iterate over a Group while
modifying it.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Group.copy">
<span class="sig-name descname"><span class="pre">copy</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Group.copy" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">duplicate the Group</span></div>
<div class="line"><span class="signature">copy() -> Group</span></div>
</div>
<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>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Group.add">
<span class="sig-name descname"><span class="pre">add</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Group.add" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">add Sprites to this Group</span></div>
<div class="line"><span class="signature">add(*sprites) -> None</span></div>
</div>
<p>Add any number of Sprites to this Group. This will only add Sprites that
are not already members of the Group.</p>
<p>Each sprite argument can also be a iterator containing Sprites.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Group.remove">
<span class="sig-name descname"><span class="pre">remove</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Group.remove" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">remove Sprites from the Group</span></div>
<div class="line"><span class="signature">remove(*sprites) -> None</span></div>
</div>
<p>Remove any number of Sprites from the Group. This will only remove
Sprites that are already members of the Group.</p>
<p>Each sprite argument can also be a iterator containing Sprites.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Group.has">
<span class="sig-name descname"><span class="pre">has</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Group.has" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">test if a Group contains Sprites</span></div>
<div class="line"><span class="signature">has(*sprites) -> bool</span></div>
</div>
<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:
..."), which tests if a single Sprite belongs to a Group.</p>
<p>Each sprite argument can also be a iterator containing Sprites.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Group.update">
<span class="sig-name descname"><span class="pre">update</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Group.update" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">call the update method on contained Sprites</span></div>
<div class="line"><span class="signature">update(*args, **kwargs) -> None</span></div>
</div>
<p>Calls the <code class="docutils literal notranslate"><span class="pre">update()</span></code> 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 <code class="docutils literal notranslate"><span class="pre">Group.update()</span></code> will be passed
to each Sprite.</p>
<p>There is no way to get the return value from the <code class="docutils literal notranslate"><span class="pre">Sprite.update()</span></code>
methods.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Group.draw">
<span class="sig-name descname"><span class="pre">draw</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Group.draw" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">blit the Sprite images</span></div>
<div class="line"><span class="signature">draw(Surface) -> List[Rect]</span></div>
</div>
<p>Draws the contained Sprites to the Surface argument. This uses the
<code class="docutils literal notranslate"><span class="pre">Sprite.image</span></code> attribute for the source surface, and <code class="docutils literal notranslate"><span class="pre">Sprite.rect</span></code>
for the position.</p>
<p>The Group does not keep sprites in any order, so the draw order is
arbitrary.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Group.clear">
<span class="sig-name descname"><span class="pre">clear</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Group.clear" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">draw a background over the Sprites</span></div>
<div class="line"><span class="signature">clear(Surface_dest, background) -> None</span></div>
</div>
<p>Erases the Sprites used in the last <code class="docutils literal notranslate"><span class="pre">Group.draw()</span></code> call. The
destination Surface is cleared by filling the drawn Sprite positions with
the background.</p>
<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>
<p>Here is an example callback that will clear the Sprites with solid red:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><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>
<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>
<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>
</pre></div>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.Group.empty">
<span class="sig-name descname"><span class="pre">empty</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.Group.empty" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">remove all Sprites</span></div>
<div class="line"><span class="signature">empty() -> None</span></div>
</div>
<p>Removes all Sprites from this Group.</p>
</dd></dl>
</dd></dl>
<dl class="py class definition">
<dt class="sig sig-object py title" id="pygame.sprite.RenderPlain">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">RenderPlain</span></span><a class="headerlink" href="#pygame.sprite.RenderPlain" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Same as pygame.sprite.Group</span></div>
</div>
<p>This class is an alias to <code class="docutils literal notranslate"><span class="pre">pygame.sprite.Group()</span></code>. It has no additional functionality.</p>
</dd></dl>
<dl class="py class definition">
<dt class="sig sig-object py title" id="pygame.sprite.RenderClear">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">RenderClear</span></span><a class="headerlink" href="#pygame.sprite.RenderClear" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Same as pygame.sprite.Group</span></div>
</div>
<p>This class is an alias to <code class="docutils literal notranslate"><span class="pre">pygame.sprite.Group()</span></code>. It has no additional functionality.</p>
</dd></dl>
<dl class="py class definition">
<dt class="sig sig-object py title" id="pygame.sprite.RenderUpdates">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">RenderUpdates</span></span><a class="headerlink" href="#pygame.sprite.RenderUpdates" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Group sub-class that tracks dirty updates.</span></div>
<div class="line"><span class="signature">RenderUpdates(*sprites) -> RenderUpdates</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 37%" />
<col style="width: 1%" />
<col style="width: 62%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.RenderUpdates.draw">pygame.sprite.RenderUpdates.draw</a></div>
</td>
<td>—</td>
<td>blit the Sprite images and track changed areas</td>
</tr>
</tbody>
</table>
<p>This class is derived from <code class="docutils literal notranslate"><span class="pre">pygame.sprite.Group()</span></code>. It has an extended
<code class="docutils literal notranslate"><span class="pre">draw()</span></code> method that tracks the changed areas of the screen.</p>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.RenderUpdates.draw">
<span class="sig-name descname"><span class="pre">draw</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.RenderUpdates.draw" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">blit the Sprite images and track changed areas</span></div>
<div class="line"><span class="signature">draw(surface) -> Rect_list</span></div>
</div>
<p>Draws all the Sprites to the surface, the same as <code class="docutils literal notranslate"><span class="pre">Group.draw()</span></code>. 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 <code class="docutils literal notranslate"><span class="pre">Group.clear()</span></code> calls.</p>
<p>The returned Rect list should be passed to <code class="docutils literal notranslate"><span class="pre">pygame.display.update()</span></code>.
This will help performance on software driven display modes. This type of
updating is usually only helpful on destinations with non-animating
backgrounds.</p>
</dd></dl>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.sprite.OrderedUpdates">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">OrderedUpdates</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.OrderedUpdates" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">RenderUpdates sub-class that draws Sprites in order of addition.</span></div>
<div class="line"><span class="signature">OrderedUpdates(*spites) -> OrderedUpdates</span></div>
</div>
<p>This class derives from <code class="docutils literal notranslate"><span class="pre">pygame.sprite.RenderUpdates()</span></code>. 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>
</dd></dl>
<dl class="py class definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">LayeredUpdates</span></span><a class="headerlink" href="#pygame.sprite.LayeredUpdates" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">LayeredUpdates is a sprite group that handles layers and draws like OrderedUpdates.</span></div>
<div class="line"><span class="signature">LayeredUpdates(*spites, **kwargs) -> LayeredUpdates</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 42%" />
<col style="width: 1%" />
<col style="width: 58%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.add">pygame.sprite.LayeredUpdates.add</a></div>
</td>
<td>—</td>
<td>add a sprite or sequence of sprites to a group</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.sprites">pygame.sprite.LayeredUpdates.sprites</a></div>
</td>
<td>—</td>
<td>returns a ordered list of sprites (first back, last top).</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.draw">pygame.sprite.LayeredUpdates.draw</a></div>
</td>
<td>—</td>
<td>draw all sprites in the right order onto the passed surface.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_sprites_at">pygame.sprite.LayeredUpdates.get_sprites_at</a></div>
</td>
<td>—</td>
<td>returns a list with all sprites at that position.</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_sprite">pygame.sprite.LayeredUpdates.get_sprite</a></div>
</td>
<td>—</td>
<td>returns the sprite at the index idx from the groups sprites</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.remove_sprites_of_layer">pygame.sprite.LayeredUpdates.remove_sprites_of_layer</a></div>
</td>
<td>—</td>
<td>removes all sprites from a layer and returns them as a list.</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.layers">pygame.sprite.LayeredUpdates.layers</a></div>
</td>
<td>—</td>
<td>returns a list of layers defined (unique), sorted from bottom up.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.change_layer">pygame.sprite.LayeredUpdates.change_layer</a></div>
</td>
<td>—</td>
<td>changes the layer of the sprite</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_layer_of_sprite">pygame.sprite.LayeredUpdates.get_layer_of_sprite</a></div>
</td>
<td>—</td>
<td>returns the layer that sprite is currently in.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_top_layer">pygame.sprite.LayeredUpdates.get_top_layer</a></div>
</td>
<td>—</td>
<td>returns the top layer</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_bottom_layer">pygame.sprite.LayeredUpdates.get_bottom_layer</a></div>
</td>
<td>—</td>
<td>returns the bottom layer</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.move_to_front">pygame.sprite.LayeredUpdates.move_to_front</a></div>
</td>
<td>—</td>
<td>brings the sprite to front layer</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.move_to_back">pygame.sprite.LayeredUpdates.move_to_back</a></div>
</td>
<td>—</td>
<td>moves the sprite to the bottom layer</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_top_sprite">pygame.sprite.LayeredUpdates.get_top_sprite</a></div>
</td>
<td>—</td>
<td>returns the topmost sprite</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.get_sprites_from_layer">pygame.sprite.LayeredUpdates.get_sprites_from_layer</a></div>
</td>
<td>—</td>
<td>returns all sprites from a layer, ordered by how they where added</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredUpdates.switch_layer">pygame.sprite.LayeredUpdates.switch_layer</a></div>
</td>
<td>—</td>
<td>switches the sprites from layer1 to layer2</td>
</tr>
</tbody>
</table>
<p>This group is fully compatible with <a class="tooltip reference internal" href="#pygame.sprite.Sprite" title=""><code class="xref py py-class docutils literal notranslate"><span class="pre">pygame.sprite.Sprite</span></code><span class="tooltip-content">Simple base class for visible game objects.</span></a>.</p>
<p>You can set the default layer through kwargs using 'default_layer' and an
integer for the layer. The default layer is 0.</p>
<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 <code class="docutils literal notranslate"><span class="pre">sprite.layer</span></code> attribute). If neither sprite
has attribute layer nor **kwarg then the default layer is used to add the
sprites.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 1.8.</span></p>
</div>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.add">
<span class="sig-name descname"><span class="pre">add</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.add" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">add a sprite or sequence of sprites to a group</span></div>
<div class="line"><span class="signature">add(*sprites, **kwargs) -> None</span></div>
</div>
<p>If the <code class="docutils literal notranslate"><span class="pre">sprite(s)</span></code> have an attribute layer then that is used for the
layer. If **kwargs contains 'layer' then the <code class="docutils literal notranslate"><span class="pre">sprite(s)</span></code> will be added
to that argument (overriding the sprite layer attribute). If neither is
passed then the <code class="docutils literal notranslate"><span class="pre">sprite(s)</span></code> will be added to the default layer.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.sprites">
<span class="sig-name descname"><span class="pre">sprites</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.sprites" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">returns a ordered list of sprites (first back, last top).</span></div>
<div class="line"><span class="signature">sprites() -> sprites</span></div>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.draw">
<span class="sig-name descname"><span class="pre">draw</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.draw" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">draw all sprites in the right order onto the passed surface.</span></div>
<div class="line"><span class="signature">draw(surface) -> Rect_list</span></div>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.get_sprites_at">
<span class="sig-name descname"><span class="pre">get_sprites_at</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_sprites_at" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">returns a list with all sprites at that position.</span></div>
<div class="line"><span class="signature">get_sprites_at(pos) -> colliding_sprites</span></div>
</div>
<p>Bottom sprites first, top last.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.get_sprite">
<span class="sig-name descname"><span class="pre">get_sprite</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_sprite" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">returns the sprite at the index idx from the groups sprites</span></div>
<div class="line"><span class="signature">get_sprite(idx) -> sprite</span></div>
</div>
<p>Raises IndexOutOfBounds if the idx is not within range.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.remove_sprites_of_layer">
<span class="sig-name descname"><span class="pre">remove_sprites_of_layer</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.remove_sprites_of_layer" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">removes all sprites from a layer and returns them as a list.</span></div>
<div class="line"><span class="signature">remove_sprites_of_layer(layer_nr) -> sprites</span></div>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.layers">
<span class="sig-name descname"><span class="pre">layers</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.layers" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">returns a list of layers defined (unique), sorted from bottom up.</span></div>
<div class="line"><span class="signature">layers() -> layers</span></div>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.change_layer">
<span class="sig-name descname"><span class="pre">change_layer</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.change_layer" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">changes the layer of the sprite</span></div>
<div class="line"><span class="signature">change_layer(sprite, new_layer) -> None</span></div>
</div>
<p>sprite must have been added to the renderer. It is not checked.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.get_layer_of_sprite">
<span class="sig-name descname"><span class="pre">get_layer_of_sprite</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_layer_of_sprite" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">returns the layer that sprite is currently in.</span></div>
<div class="line"><span class="signature">get_layer_of_sprite(sprite) -> layer</span></div>
</div>
<p>If the sprite is not found then it will return the default layer.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.get_top_layer">
<span class="sig-name descname"><span class="pre">get_top_layer</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_top_layer" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">returns the top layer</span></div>
<div class="line"><span class="signature">get_top_layer() -> layer</span></div>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.get_bottom_layer">
<span class="sig-name descname"><span class="pre">get_bottom_layer</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_bottom_layer" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">returns the bottom layer</span></div>
<div class="line"><span class="signature">get_bottom_layer() -> layer</span></div>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.move_to_front">
<span class="sig-name descname"><span class="pre">move_to_front</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.move_to_front" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">brings the sprite to front layer</span></div>
<div class="line"><span class="signature">move_to_front(sprite) -> None</span></div>
</div>
<p>Brings the sprite to front, changing sprite layer to topmost layer (added
at the end of that layer).</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.move_to_back">
<span class="sig-name descname"><span class="pre">move_to_back</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.move_to_back" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">moves the sprite to the bottom layer</span></div>
<div class="line"><span class="signature">move_to_back(sprite) -> None</span></div>
</div>
<p>Moves the sprite to the bottom layer, moving it behind all other layers
and adding one additional layer.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.get_top_sprite">
<span class="sig-name descname"><span class="pre">get_top_sprite</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_top_sprite" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">returns the topmost sprite</span></div>
<div class="line"><span class="signature">get_top_sprite() -> Sprite</span></div>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.get_sprites_from_layer">
<span class="sig-name descname"><span class="pre">get_sprites_from_layer</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.get_sprites_from_layer" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">returns all sprites from a layer, ordered by how they where added</span></div>
<div class="line"><span class="signature">get_sprites_from_layer(layer) -> sprites</span></div>
</div>
<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>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredUpdates.switch_layer">
<span class="sig-name descname"><span class="pre">switch_layer</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredUpdates.switch_layer" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">switches the sprites from layer1 to layer2</span></div>
<div class="line"><span class="signature">switch_layer(layer1_nr, layer2_nr) -> None</span></div>
</div>
<p>The layers number must exist, it is not checked.</p>
</dd></dl>
</dd></dl>
<dl class="py class definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredDirty">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">LayeredDirty</span></span><a class="headerlink" href="#pygame.sprite.LayeredDirty" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">LayeredDirty group is for DirtySprite objects. Subclasses LayeredUpdates.</span></div>
<div class="line"><span class="signature">LayeredDirty(*spites, **kwargs) -> LayeredDirty</span></div>
</div>
<table class="toc docutils align-default">
<colgroup>
<col style="width: 37%" />
<col style="width: 1%" />
<col style="width: 62%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.draw">pygame.sprite.LayeredDirty.draw</a></div>
</td>
<td>—</td>
<td>draw all sprites in the right order onto the passed surface.</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.clear">pygame.sprite.LayeredDirty.clear</a></div>
</td>
<td>—</td>
<td>used to set background</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.repaint_rect">pygame.sprite.LayeredDirty.repaint_rect</a></div>
</td>
<td>—</td>
<td>repaints the given area</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.set_clip">pygame.sprite.LayeredDirty.set_clip</a></div>
</td>
<td>—</td>
<td>clip the area where to draw. Just pass None (default) to reset the clip</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.get_clip">pygame.sprite.LayeredDirty.get_clip</a></div>
</td>
<td>—</td>
<td>clip the area where to draw. Just pass None (default) to reset the clip</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.change_layer">pygame.sprite.LayeredDirty.change_layer</a></div>
</td>
<td>—</td>
<td>changes the layer of the sprite</td>
</tr>
<tr class="row-odd"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.set_timing_treshold">pygame.sprite.LayeredDirty.set_timing_treshold</a></div>
</td>
<td>—</td>
<td>sets the threshold in milliseconds</td>
</tr>
<tr class="row-even"><td><div class="line"><a class="toc reference external" href="sprite.html#pygame.sprite.LayeredDirty.set_timing_threshold">pygame.sprite.LayeredDirty.set_timing_threshold</a></div>
</td>
<td>—</td>
<td>sets the threshold in milliseconds</td>
</tr>
</tbody>
</table>
<p>This group requires <a class="tooltip reference internal" href="#pygame.sprite.DirtySprite" title=""><code class="xref py py-class docutils literal notranslate"><span class="pre">pygame.sprite.DirtySprite</span></code><span class="tooltip-content">A subclass of Sprite with more attributes and features.</span></a> or any sprite that
has the following attributes:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">image</span><span class="p">,</span> <span class="n">rect</span><span class="p">,</span> <span class="n">dirty</span><span class="p">,</span> <span class="n">visible</span><span class="p">,</span> <span class="n">blendmode</span> <span class="p">(</span><span class="n">see</span> <span class="n">doc</span> <span class="n">of</span> <span class="n">DirtySprite</span><span class="p">)</span><span class="o">.</span>
</pre></div>
</div>
<p>It uses the dirty flag technique and is therefore faster than the
<a class="tooltip reference internal" href="#pygame.sprite.RenderUpdates" title=""><code class="xref py py-class docutils literal notranslate"><span class="pre">pygame.sprite.RenderUpdates</span></code><span class="tooltip-content">Group sub-class that tracks dirty updates.</span></a> if you have many static sprites. It
also switches automatically between dirty rect update and full screen
drawing, so you do not have to worry what would be faster.</p>
<p>Same as for the <a class="tooltip reference internal" href="#pygame.sprite.Group" title=""><code class="xref py py-class docutils literal notranslate"><span class="pre">pygame.sprite.Group</span></code><span class="tooltip-content">A container class to hold and manage multiple Sprite objects.</span></a>. You can specify some
additional attributes through kwargs:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">_use_update</span><span class="p">:</span> <span class="kc">True</span><span class="o">/</span><span class="kc">False</span> <span class="n">default</span> <span class="ow">is</span> <span class="kc">False</span>
<span class="n">_default_layer</span><span class="p">:</span> <span class="n">default</span> <span class="n">layer</span> <span class="n">where</span> <span class="n">sprites</span> <span class="n">without</span> <span class="n">a</span> <span class="n">layer</span> <span class="n">are</span> <span class="n">added</span><span class="o">.</span>
<span class="n">_time_threshold</span><span class="p">:</span> <span class="n">threshold</span> <span class="n">time</span> <span class="k">for</span> <span class="n">switching</span> <span class="n">between</span> <span class="n">dirty</span> <span class="n">rect</span> <span class="n">mode</span>
<span class="ow">and</span> <span class="n">fullscreen</span> <span class="n">mode</span><span class="p">,</span> <span class="n">defaults</span> <span class="n">to</span> <span class="mf">1000.</span><span class="o">/</span><span class="mi">80</span> <span class="o">==</span> <span class="mf">1000.</span><span class="o">/</span><span class="n">fps</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 1.8.</span></p>
</div>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredDirty.draw">
<span class="sig-name descname"><span class="pre">draw</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredDirty.draw" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">draw all sprites in the right order onto the passed surface.</span></div>
<div class="line"><span class="signature">draw(surface, bgd=None) -> Rect_list</span></div>
</div>
<p>You can pass the background too. If a background is already set, then the
bgd argument has no effect.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredDirty.clear">
<span class="sig-name descname"><span class="pre">clear</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredDirty.clear" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">used to set background</span></div>
<div class="line"><span class="signature">clear(surface, bgd) -> None</span></div>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredDirty.repaint_rect">
<span class="sig-name descname"><span class="pre">repaint_rect</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredDirty.repaint_rect" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">repaints the given area</span></div>
<div class="line"><span class="signature">repaint_rect(screen_rect) -> None</span></div>
</div>
<p>screen_rect is in screen coordinates.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredDirty.set_clip">
<span class="sig-name descname"><span class="pre">set_clip</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredDirty.set_clip" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">clip the area where to draw. Just pass None (default) to reset the clip</span></div>
<div class="line"><span class="signature">set_clip(screen_rect=None) -> None</span></div>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredDirty.get_clip">
<span class="sig-name descname"><span class="pre">get_clip</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredDirty.get_clip" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">clip the area where to draw. Just pass None (default) to reset the clip</span></div>
<div class="line"><span class="signature">get_clip() -> Rect</span></div>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredDirty.change_layer">
<span class="sig-name descname"><span class="pre">change_layer</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredDirty.change_layer" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">changes the layer of the sprite</span></div>
<div class="line"><span class="signature">change_layer(sprite, new_layer) -> None</span></div>
</div>
<p>sprite must have been added to the renderer. It is not checked.</p>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredDirty.set_timing_treshold">
<span class="sig-name descname"><span class="pre">set_timing_treshold</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredDirty.set_timing_treshold" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">sets the threshold in milliseconds</span></div>
<div class="line"><span class="signature">set_timing_treshold(time_ms) -> None</span></div>
</div>
<p>DEPRECATED: Use set_timing_threshold() instead.</p>
<div class="deprecated">
<p><span class="versionmodified deprecated">Deprecated since pygame 2.1.1.</span></p>
</div>
</dd></dl>
<dl class="py method definition">
<dt class="sig sig-object py title" id="pygame.sprite.LayeredDirty.set_timing_threshold">
<span class="sig-name descname"><span class="pre">set_timing_threshold</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.LayeredDirty.set_timing_threshold" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">sets the threshold in milliseconds</span></div>
<div class="line"><span class="signature">set_timing_threshold(time_ms) -> None</span></div>
</div>
<p>Defaults to 1000.0 / 80.0. This means that the screen will be painted
using the flip method rather than the update method if the update
method is taking so long to update the screen that the frame rate falls
below 80 frames per second.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 2.1.1.</span></p>
</div>
<dl class="field-list simple">
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><p><strong>TypeError</strong> -- if <code class="docutils literal notranslate"><span class="pre">time_ms</span></code> is not int or float</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.sprite.GroupSingle">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">GroupSingle</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.GroupSingle" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Group container that holds a single sprite.</span></div>
<div class="line"><span class="signature">GroupSingle(sprite=None) -> GroupSingle</span></div>
</div>
<p>The GroupSingle container only holds a single Sprite. When a new Sprite is
added, the old one is removed.</p>
<p>There is a special property, <code class="docutils literal notranslate"><span class="pre">GroupSingle.sprite</span></code>, 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>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.sprite.spritecollide">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">spritecollide</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.spritecollide" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Find sprites in a group that intersect another sprite.</span></div>
<div class="line"><span class="signature">spritecollide(sprite, group, dokill, collided = None) -> Sprite_list</span></div>
</div>
<p>Return a list containing all Sprites in a Group that intersect with another
Sprite. Intersection is determined by comparing the <code class="docutils literal notranslate"><span class="pre">Sprite.rect</span></code>
attribute of each Sprite.</p>
<p>The dokill argument is a bool. If set to True, all Sprites that collide will
be removed from the Group.</p>
<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>
<p>collided callables:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><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>
<span class="n">collide_circle_ratio</span><span class="p">,</span> <span class="n">collide_mask</span>
</pre></div>
</div>
<p>Example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># See if the Sprite block has collided with anything in the Group block_list</span>
<span class="c1"># The True flag will remove the sprite in block_list</span>
<span class="n">blocks_hit_list</span> <span class="o">=</span> <span class="n">pygame</span><span class="o">.</span><span class="n">sprite</span><span class="o">.</span><span class="n">spritecollide</span><span class="p">(</span><span class="n">player</span><span class="p">,</span> <span class="n">block_list</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
<span class="c1"># Check the list of colliding sprites, and add one to the score for each one</span>
<span class="k">for</span> <span class="n">block</span> <span class="ow">in</span> <span class="n">blocks_hit_list</span><span class="p">:</span>
<span class="n">score</span> <span class="o">+=</span><span class="mi">1</span>
</pre></div>
</div>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.sprite.collide_rect">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">collide_rect</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.collide_rect" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Collision detection between two sprites, using rects.</span></div>
<div class="line"><span class="signature">collide_rect(left, right) -> bool</span></div>
</div>
<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>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 1.8.</span></p>
</div>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.sprite.collide_rect_ratio">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">collide_rect_ratio</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.collide_rect_ratio" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Collision detection between two sprites, using rects scaled to a ratio.</span></div>
<div class="line"><span class="signature">collide_rect_ratio(ratio) -> collided_callable</span></div>
</div>
<p>A callable class that checks for collisions between two sprites, using a
scaled version of the sprites rects.</p>
<p>Is created with a ratio, the instance is then intended to be passed as a
collided callback function to the *collide functions.</p>
<p>A ratio is a floating point number - 1.0 is the same size, 2.0 is twice as
big, and 0.5 is half the size.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 1.8.1.</span></p>
</div>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.sprite.collide_circle">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">collide_circle</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.collide_circle" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Collision detection between two sprites, using circles.</span></div>
<div class="line"><span class="signature">collide_circle(left, right) -> bool</span></div>
</div>
<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>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 1.8.1.</span></p>
</div>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.sprite.collide_circle_ratio">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">collide_circle_ratio</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.collide_circle_ratio" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Collision detection between two sprites, using circles scaled to a ratio.</span></div>
<div class="line"><span class="signature">collide_circle_ratio(ratio) -> collided_callable</span></div>
</div>
<p>A callable class that checks for collisions between two sprites, using a
scaled version of the sprites radius.</p>
<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>
<p>A ratio is a floating point number - 1.0 is the same size, 2.0 is twice as
big, and 0.5 is half the size.</p>
<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>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 1.8.1.</span></p>
</div>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.sprite.collide_mask">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">collide_mask</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.collide_mask" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Collision detection between two sprites, using masks.</span></div>
<div class="line"><span class="signature">collide_mask(sprite1, sprite2) -> (int, int)</span></div>
<div class="line"><span class="signature">collide_mask(sprite1, sprite2) -> None</span></div>
</div>
<p>Tests for collision between two sprites, by testing if their bitmasks
overlap (uses <a class="tooltip reference internal" href="mask.html#pygame.mask.Mask.overlap" title=""><code class="xref py py-func docutils literal notranslate"><span class="pre">pygame.mask.Mask.overlap()</span></code><span class="tooltip-content">Returns the point of intersection</span></a>). If the sprites have a
<code class="docutils literal notranslate"><span class="pre">mask</span></code> attribute, it is used as the mask, otherwise a mask is created from
the sprite's <code class="docutils literal notranslate"><span class="pre">image</span></code> (uses <a class="tooltip reference internal" href="mask.html#pygame.mask.from_surface" title=""><code class="xref py py-func docutils literal notranslate"><span class="pre">pygame.mask.from_surface()</span></code><span class="tooltip-content">Creates a Mask from the given surface</span></a>). Sprites must
have a <code class="docutils literal notranslate"><span class="pre">rect</span></code> attribute; the <code class="docutils literal notranslate"><span class="pre">mask</span></code> attribute is optional.</p>
<p>The first point of collision between the masks is returned. The collision
point is offset from <code class="docutils literal notranslate"><span class="pre">sprite1</span></code>'s mask's topleft corner (which is always
(0, 0)). The collision point is a position within the mask and is not
related to the actual screen position of <code class="docutils literal notranslate"><span class="pre">sprite1</span></code>.</p>
<p>This function is intended to be passed as a <code class="docutils literal notranslate"><span class="pre">collided</span></code> callback function
to the group collide functions (see <a class="reference internal" href="#pygame.sprite.spritecollide" title="pygame.sprite.spritecollide"><code class="xref py py-meth docutils literal notranslate"><span class="pre">spritecollide()</span></code></a>,
<a class="reference internal" href="#pygame.sprite.groupcollide" title="pygame.sprite.groupcollide"><code class="xref py py-meth docutils literal notranslate"><span class="pre">groupcollide()</span></code></a>, <a class="reference internal" href="#pygame.sprite.spritecollideany" title="pygame.sprite.spritecollideany"><code class="xref py py-meth docutils literal notranslate"><span class="pre">spritecollideany()</span></code></a>).</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>To increase performance, create and set a <code class="docutils literal notranslate"><span class="pre">mask</span></code> attibute for all
sprites that will use this function to check for collisions. Otherwise,
each time this function is called it will create new masks.</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>A new mask needs to be recreated each time a sprite's image is changed
(e.g. if a new image is used or the existing image is rotated).</p>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Example of mask creation for a sprite.</span>
<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>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>first point of collision between the masks or <code class="docutils literal notranslate"><span class="pre">None</span></code> if no
collision</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>tuple(int, int) or NoneType</p>
</dd>
</dl>
<div class="versionadded">
<p><span class="versionmodified added">New in pygame 1.8.0.</span></p>
</div>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.sprite.groupcollide">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">groupcollide</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.groupcollide" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Find all sprites that collide between two groups.</span></div>
<div class="line"><span class="signature">groupcollide(group1, group2, dokill1, dokill2, collided = None) -> Sprite_dict</span></div>
</div>
<p>This will find collisions between all the Sprites in two groups.
Collision is determined by comparing the <code class="docutils literal notranslate"><span class="pre">Sprite.rect</span></code> attribute of
each Sprite or by using the collided function if it is not None.</p>
<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>
<p>If either dokill argument is True, the colliding Sprites will be removed
from their respective Group.</p>
<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, then all
sprites must have a "rect" value, which is a rectangle of the sprite area,
which will be used to calculate the collision.</p>
</dd></dl>
<dl class="py function definition">
<dt class="sig sig-object py title" id="pygame.sprite.spritecollideany">
<span class="sig-prename descclassname"><span class="pre">pygame.sprite.</span></span><span class="sig-name descname"><span class="pre">spritecollideany</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#pygame.sprite.spritecollideany" title="Permalink to this definition">¶</a></dt>
<dd><div class="line-block">
<div class="line"><span class="summaryline">Simple test if a sprite intersects anything in a group.</span></div>
<div class="line"><span class="signature">spritecollideany(sprite, group, collided = None) -> Sprite</span> Collision with the returned sprite.</div>
<div class="line"><span class="signature">spritecollideany(sprite, group, collided = None) -> None</span> No collision</div>
</div>
<p>If the sprite collides with any single sprite in the group, a single
sprite from the group is returned. On no collision None is returned.</p>
<p>If you don't need all the features of the <code class="docutils literal notranslate"><span class="pre">pygame.sprite.spritecollide()</span></code> function, this
function will be a bit quicker.</p>
<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, then all
sprites must have a "rect" value, which is a rectangle of the sprite area,
which will be used to calculate the collision.</p>
</dd></dl>
</dd></dl>
</section>
<br /><br />
<hr />
<a href="https://github.com/pygame/pygame/edit/main/docs/reST/ref/sprite.rst" rel="nofollow">Edit on GitHub</a>
<div class="clearer"></div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="surface.html" title="pygame.Surface"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="sndarray.html" title="pygame.sndarray"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">pygame v2.1.2 documentation</a> »</li>
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">pygame.sprite</span></code></a></li>
<script type="text/javascript" src="https://www.pygame.org/comment/jquery.plugin.docscomments.js"></script>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2000-2021, pygame developers.
</div>
</body>
</html>
|