annotate docs/tut/SpriteIntro.html @ 3172:d1b367fc08bc tests-returncode

Use a return code of 1 when the tests fail.
author Thomas Kluyver <takowl@gmail.com>
date Wed, 09 Jan 2013 10:13:57 +0000
parents 0102516f9724
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
1 <html><head><!--
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
2 TUTORIAL:Sprite Module Introduction
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
3 -->
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
4 <title>Pygame Tutorials - Sprite Module Intoduction</title>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
5 </head>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
6 <body>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
7
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
8 <h1 align="center"><font size="-1">Pygame Tutorials</font><br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
9 Sprite Module Introduction</h1>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
10
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
11 <h2 align="center">by Pete Shinners<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
12 <font size="-1">pete@shinners.org</font></h2>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
13
363
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
14 <h3 align="center">Revision 1.1, April 12th, 2002</h3>
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
15 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
16 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
17 Pygame version 1.3 comes with a new module, pygame.sprite. This module
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
18 is written in python and includes some higher level classes to manage your
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
19 game objects. By using this module to its full potential, you can easily
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
20 manage and draw your game objects. The sprite classes are very optimized,
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
21 so it's likely your game will run faster with the sprite module than without.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
22 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
23 The sprite module is also meant to be very generic. It turns out you can
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
24 use it with nearly any type of gameplay. All this flexibility comes with a
1423
0102516f9724 Pygame docs: fixed some links
Lenard Lindstrom <len-l@telus.net>
parents: 531
diff changeset
25 slight penalty, it needs a little understanding to properly use it. The <a href="../ref/sprite.html">
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
26 reference documentation</a> for the sprite module can keep you running, but
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
27 you'll probably need a bit more explanation of how to use pygame.sprite in
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
28 your own game.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
29 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
30 Several of the pygame examples (like "chimp" and "aliens") have been updated
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
31 to use the sprite module. You may want to look into those first to see what
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
32 this sprite module is all about. The chimp module even has it's own line-by-line
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
33 tutorial, which may help get more an understanding of programming with python
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
34 and pygame.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
35 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
36 Note that this introduction will assume you have a bit of experience programming
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
37 with python, and are somewhat framiliar with the different parts of creating
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
38 a simple game. In this tutorial the word "reference" is occasianally used.
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
39 This represents a python variable. Variables in python are references, so
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
40 you can have several variables all pointing to the same object.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
41 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
42
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
43 <h2>History Lesson</h2>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
44 The term "sprite" is a holdover from older computer and game machines.
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
45 These older boxes were unable to draw and erase normal graphics fast enough
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
46 for them to work as games. These machines had special hardware to handle
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
47 game like objects that needed to animate very quickly. These objects were
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
48 called 'sprites' and had special limitations, but could be drawn and updated
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
49 very fast. They usually existed in special overlay buffers in the video.
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
50 These days computers have become generally fast enough to handle sprite like
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
51 objects without dedicated hardware. The term sprite is still used to represent
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
52 just about anything in a 2D game that is animated.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
53 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
54 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
55
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
56 <h2>The Classes</h2>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
57 The sprite module comes with two main classes. The first is Sprite, which
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
58 should be used as a base class for all your game objects. This class doesn't
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
59 really do anything on its own, it just includes several functions to help
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
60 manage the game object. The other type of class is Group. The Group class
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
61 is a container for different Sprite objects. There are actually several different
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
62 types of group classes. Some of the Groups can draw all the elements they
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
63 contain, for example.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
64 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
65 This is all there really is to it. We'll start with a description of what
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
66 each type of class does, and then discuss the proper ways to use these two
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
67 classes.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
68 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
69
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
70 <h2>The Sprite Class</h2>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
71 As mentioned before, the Sprite class is designed to be a base class for
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
72 all your game objects. You cannot really use it on its own, as it only has
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
73 several methods to help it work with the different Group classes. The sprite
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
74 keeps track of which groups it belongs to. The class constructor (__init__
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
75 method) takes an argument of a Group (or list of Groups) the Sprite instance
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
76 should belong to. You can also change the Group membership for the Sprite
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
77 with the add() and remove() methods. There is also a groups() method, which
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
78 returns a list of the current groups containing the sprite.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
79 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
80 When using the your Sprite classes it's best to think of them as "valid"
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
81 or "alive" when they are belonging to one or more Groups. When you remove
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
82 the instance from all groups pygame will clean up the object. (Unless you
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
83 have your own references to the instance somewhere else.) The kill() method
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
84 removes the sprite from all groups it belongs to. This will cleanly delete
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
85 the sprite object. If you've put some little games together, you'll know sometimes
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
86 cleanly deleting a game object can be tricky. The sprite also comes with
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
87 an alive() method, which returns true if it is still a member of any groups.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
88 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
89 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
90
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
91 <h2>The Group Class</h2>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
92 The Group class is just a simple container. Similar to the sprite, it has
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
93 an add() and remove() method which can change which sprites belong to the
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
94 group. You also can pass a sprite or list of sprites to the contructor (__init__
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
95 method) to create a Group instance that contains some initial sprites.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
96 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
97 The Group has a few other methods like empty() to remove all sprites from
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
98 the group and copy() which will return a copy of the group with all the same
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
99 members. Also the has() method will quickly check if the Group contains a
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
100 sprite or list of sprites.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
101 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
102 The other function you will use frequently is the sprites() method. This
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
103 returns an object that can be looped on to access every sprite the group contains.
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
104 Currently this is just a list of the sprites, but in later version of python
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
105 this will likely use iterators for better performance.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
106 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
107 As a shortcut, the Group also has an update() method, which will call an
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
108 update() method on every sprite in the group. Passing the same arguments to
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
109 each one. Usually in a game you need some function that updates the state
315
bd6529943559 sprite intro fixes
pygame
parents: 284
diff changeset
110 of a game object. It's very easy to call your own methods using the Group.sprites()
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
111 method, but this is a shortcut that's used enough to be included. Also note
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
112 that the base Sprite class has a "dummy" update() method that takes any sort
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
113 of arguments and does nothing.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
114 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
115 Lastly, the Group has a couple other methods that allow you to use it with
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
116 the builtlin len() method, getting the number of sprites it contains. and
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
117 the "truth" operator, which allows you to do "if mygroup:" to check if the
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
118 group has any sprites.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
119 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
120
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
121 <h2>Mixing Them Together</h2>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
122 At this point the two classes seem pretty basic. Not doing a lot more than
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
123 you can do with a simple list and your own class of game objects. But there
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
124 are some big advantages to using the Sprite and Group together. A sprite can
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
125 belong to as many groups as you want. Remember as soon as it belongs to no
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
126 groups, it will usually be cleared up (unless you have other "non-group" references
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
127 to that object)<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
128 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
129 The first big thing is a fast simple way to categorize sprites. For example,
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
130 say we had a pacman-like game. We could make separate groups for the different
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
131 types of objects in the game. Ghosts, Pac, and Pellets. When pac eats a power
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
132 pellet, we can change the state for all ghost objects by effecting everything
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
133 in the Ghost group. This is quicker and simpler than looping through a list
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
134 of all the game objects and checking which ones are ghosts.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
135 <br>
315
bd6529943559 sprite intro fixes
pygame
parents: 284
diff changeset
136 Adding and removing groups and sprites from each other is a very fast operation,
bd6529943559 sprite intro fixes
pygame
parents: 284
diff changeset
137 quicker than using lists to store everything. Therefore you can very
bd6529943559 sprite intro fixes
pygame
parents: 284
diff changeset
138 efficiently change group memberships. Groups can be used to work
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
139 like simple attributes for each game object. Instead of tracking some attribute
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
140 like "close_to_player" for a bunch of enemy objects, you could add them to
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
141 a separate group. Then when you need to access all the enemies that are near
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
142 the player, you already have a list of them, instead of going through a list
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
143 of all the enemies, checking for the "close_to_player" flag. Later on your
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
144 game could add multiple players, and instead of adding more "close_to_player2",
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
145 "close_to_player3" attributes, you can easily add them to different groups
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
146 for each player.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
147 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
148 Another important benefit of using the Sprites and Groups, the groups cleanly
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
149 handle the deleting (or killing) of game objects. In a game where many objects
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
150 are referencing other objects, sometimes deleting an object can be the hardest
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
151 part, since it can't go away until it is not referenced by anyone. Say we
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
152 have an object that is "chasing" another object. The chaser can keep a simple
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
153 Group that references the object (or objects) it is chasing. If the object
315
bd6529943559 sprite intro fixes
pygame
parents: 284
diff changeset
154 being chased happens to be destroyed, we don't need to worry about notifying
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
155 the chaser to stop chasing. The chaser can see for itself that its group is
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
156 now empty, and perhaps find a new target.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
157 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
158 Again, the thing to remember is that adding and removing sprites from groups
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
159 is a very cheap/fast operation. You may be best off by adding many groups
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
160 to contain and organize your game objects. Some could even be empty for large
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
161 portions of the game, there isn't any penalties for managing your game like
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
162 this.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
163 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
164
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
165 <h2>The Many Group Types</h2>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
166 The above examples and reasons to use Sprites and Groups are only a tip
315
bd6529943559 sprite intro fixes
pygame
parents: 284
diff changeset
167 of the iceberg. Another advantage is that the sprite module comes with
bd6529943559 sprite intro fixes
pygame
parents: 284
diff changeset
168 several different types of Groups. These groups all work just like a regular
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
169 old Group, but they also have added functionality (or slightly different functionality).
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
170 Here's a list of the Group classes included with the sprite module.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
171
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
172 <blockquote><b>Group</b><br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
173 This is the standard "no frills" group mainly explained above. Most of the
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
174 other Groups are derived from this one, but not all.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
175 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
176 <b>GroupSingle<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
177 </b>This works exactly like the regular Group class, but it only contains
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
178 the most recently added sprite. Therefore when you add a sprite to this group,
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
179 it "forgets" about any previous sprites it had. Therefore it always contains
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
180 only one or zero sprites.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
181 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
182 <b>RenderPlain<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
183 </b>This is a standard group derived from Group. It has a draw() method
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
184 that draws all the sprites it contains to the screen (or any Surface). For
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
185 this to work, it requires all sprites it contains to have a "image" and "rect"
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
186 attributes. It uses these to know what to blit, and where to blit it. <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
187 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
188 <b>RenderClear<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
189 </b>This is derived from the RenderPlain group, and adds a method named
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
190 clear(). This will erase the previous position of all drawn sprites. It uses
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
191 a background image to fill in the areas where the sprite were. It is smart
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
192 enough to handle deleted sprites and properly clear them from the screen when
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
193 the clear() method is called.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
194 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
195 <b>RenderUpdates</b><br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
196 This is the cadillac of rendering Groups. It is inherited from RenderClear,
315
bd6529943559 sprite intro fixes
pygame
parents: 284
diff changeset
197 but changes the draw() method to also return a list of pygame Rects, which represent
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
198 all the areas onscreen that have been changed.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
199 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
200 </blockquote>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
201 That is the list of different groups available We'll discuss more about
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
202 these rendering groups in the next section. There's nothing stopping you
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
203 from creating your own Group classes as well. They are just python code,
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
204 so you can inherit from one of these and add/change whatever you want. In
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
205 the future I hope we can add a couple more Groups to this list. A GroupMulti
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
206 which is like the GroupSingle, but can hold up to a given number of sprites
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
207 (in some sort of circular buffer?). Also a super-render group that can clear
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
208 the position of the old sprites without needing a background image to do
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
209 it (by grabbing a copy of the screen before blitting). Who knows really,
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
210 but in the future we can add more useful classes to this list.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
211 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
212
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
213 <h2>The Rendering Groups</h2>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
214 From above we can see there are three different rendering groups. We could
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
215 probably just get away with the RenderUpdates one, but it adds overhead not
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
216 really needed for something like a scrolling game. So we have a couple tools
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
217 here, pick the right one for the right job.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
218 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
219 For a scrolling type game, where the background completely changes every
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
220 frame. We obviously don't need to worry about python's update rectangles in
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
221 the call to display.update(). You should definitely go with the RenderPlain
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
222 group here to manage your rendering.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
223 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
224 For games where the background is more stationary, you definitely don't
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
225 want pygame updating the entire screen (since it doesn't need to). This type
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
226 of game usually involves erasing the old position of each object, then drawing
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
227 it in a new place for each frame. This way we are only changing what is necessary.
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
228 Most of the time you will just want to use the RenderUpdates class here. Since
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
229 you will also want to pass this list of changes to the display.update() function.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
230 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
231 The RenderUpdates class also does a good job an minimizing
531
pygame
parents: 363
diff changeset
232 overlapping areas in the list of updated rectangles. If the previous position
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
233 and current position of an object overlap, it will merge them into a single
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
234 rectangle. Combine this with the fact that is properly handles deleted objects
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
235 and this is one powerful Group class. If you've written a game that manages
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
236 the changed rectangles for the objects in a game, you know this the cause
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
237 for a lot of messy code in your game. Especially once you start to throw in
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
238 objects that can be deleted at anytime. All this work is reduced down to
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
239 a clear() and draw() method with this monster class. Plus with the overlap
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
240 checking, it is likely faster than if you did it yourself.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
241 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
242 Also note that there's nothing stopping you from mixing and matching these
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
243 render groups in your game. You should definitely use multiple rendering groups
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
244 when you want to do layering with your sprites. Also if the screen is split into
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
245 multiple sections, perhaps each section of the screen should use an appropriate
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
246 render group?<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
247 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
248
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
249
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
250 <h2>Collision Detection</h2>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
251 The sprite module also comes with two very generic collision detection functions.
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
252 For more complex games, these really won't work for you, but you can easily
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
253 grab the sourcecode for them, and modify them as needed.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
254 Here's a summary of what they are, and what they do.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
255
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
256 <blockquote><b>spritecollide(sprite, group, dokill) -&gt; list<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
257 </b>This checks for collisions between a single sprite and the sprites
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
258 in a group. It requires a "rect" attribute for all the sprites used. It returns
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
259 a list of all the sprites that overlap with the first sprite. The "dokill"
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
260 argument is a boolean argument. If it is true, the function will call the
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
261 kill() method on all the sprites. This means the last reference to each sprite
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
262 is probably in the returned list. Once the list goes away so do the sprites.
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
263 A quick example of using this in a loop,<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
264
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
265 <pre> &gt;&gt;&gt; for bomb in sprite.spritecollide(player, bombs, 1):<br> ... boom_sound.play()<br> ... Explosion(bomb, 0)<br></pre>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
266 This finds all the sprites in the "bomb" group that collide with the player.
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
267 Because of the "dokill" argument it deletes all the crashed bombs. For each
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
268 bomb that did collide, it plays a "boom" sound effect, and creates a new Explosion
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
269 where the bomb was. (Note, the Explosion class here knows to add each instance
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
270 to the appropriate class, so we don't need to store it in a variable, that
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
271 last line might feel a little "funny" to you python programmers.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
272 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
273 <b>groupcollide(group1, group2, dokill1, dokill2) -&gt; dictionary</b><br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
274 This is similar to the spritecollide function, but a little more complex.
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
275 It checks for collisions for all the sprites in one group, to the sprites
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
276 in another. There is a dokill argument for the sprites in each list. When
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
277 dokill1 is true, the colliding sprites in group1 will be kill()ed. When dokill2
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
278 is true, we get the same results for group2. The dictionary it returns works
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
279 like this; each key in the dictionary is a sprite from group1 that had a collision.
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
280 The value for that key is a list of the sprites that it collided with. Perhaps
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
281 another quick code sample explains it best<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
282
363
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
283 <pre> &gt;&gt;&gt; for alien in sprite.groupcollide(aliens, shots, 1, 1).keys()
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
284 ... boom_sound.play()
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
285 ... Explosion(alien, 0)
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
286 ... kills += 1
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
287 </pre>
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
288 This code checks for the collisions between player bullets and all the aliens
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
289 they might intersect. In this case we only loop over the dictionary keys,
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
290 but we could loop over the values() or items() if we wanted to do something
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
291 to the specific shots that collided with aliens. If we did loop over the values()
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
292 we would be looping through lists that contain sprites. The same sprite may
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
293 even appear more than once in these different loops, since the same "shot"
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
294 could have collided against multiple "aliens".<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
295 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
296 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
297 </blockquote>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
298 Those are the basic collision functions that come with pygame. It should
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
299 be easy to roll your own that perhaps use something differen than the "rect"
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
300 attribute. Or maybe try to fine-tweak your code a little more by directly
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
301 effecting the collision object, instead of building a list of the collision?
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
302 The code in the sprite collision functions is very optimized, but you could
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
303 speed it up slightly by taking out some functionality you don't need.<br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
304 <br>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
305
363
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
306 <h2>Common Problems</h2>
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
307 <p>Currently there is one main problem that catches new users. When you
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
308 derive your new sprite class with the Sprite base, you <b>must</b> call the
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
309 Sprite.__init__() method from your own class __init__() method. If you forget
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
310 to call the Sprite.__init__() method, you get a cryptic error, like this;
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
311 <tt>AttributeError: 'mysprite' instance has no attribute '_Sprite__g'</tt>.
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
312 </p>
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
313 <br>
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
314
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
315 <h2>Extending Your Own Classes <i>(Advanced)</i></h2>
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
316
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
317 <p>Because of speed concerns, the current Group classes try to
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
318 only do exactly what they need, and not handle a lot of general situations. If you
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
319 decide you need extra features, you may want to create your own Group class.</p>
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
320
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
321 <p>The Sprite and Group classes were designed to be extended, so feel free
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
322 to create your own Group classes to do specialized things. The best place to start
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
323 is probably the actual python source code for the sprite module. Looking at the
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
324 current Sprite groups should be enough example on how to create your own.</p>
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
325
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
326 <p>For example, here is the source code for a rendering Group that calls a
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
327 render() method for each sprite, instead of just blitting an "image" variable from it.
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
328 Since we want it to also handle updated areas, we will start with a copy of the original
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
329 RenderUpdates group, here is the code:
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
330 <pre>
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
331 class RenderUpdatesDraw(RenderClear):
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
332 """call sprite.draw(screen) to render sprites"""
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
333 def draw(self, surface):
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
334 dirty = self.lostsprites
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
335 self.lostsprites = []
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
336 for s, r in self.spritedict.items():
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
337 newrect = s.draw(screen) #Here's the big change
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
338 if r is 0:
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
339 dirty.append(newrect)
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
340 else:
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
341 dirty.append(newrect.union(r))
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
342 self.spritedict[s] = newrect
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
343 return dirty
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
344 </pre></p>
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
345
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
346 <p>Following is more information on how you could create your own Sprite
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
347 and Group objects from scratch. </p>
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
348
363
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
349 <p>The Sprite objects only "require" two methods. "add_internal()" and "remove_internal()".
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
350 These are called by the Group classes when they are removing a sprite from
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
351 themselves. The add_internal() and remove_internal() have a single argument
363
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
352 which is a group. Your Sprite will need some way to also keep
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
353 track of the Groups it belongs to. You will likely want to try to match the
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
354 other methods and arguments to the real Sprite class, but if you're not going
363
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
355 to use those methods, you sure don't need them.</p>
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
356
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
357 <p>It is almost the same requirements for creating your own Group. In
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
358 fact, if you look at the source you'll see the GroupSingle isn't derived from
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
359 the Group class, it just implements the same methods so you can't really tell
363
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
360 the difference. Again you need an "add_internal()" and "remove_internal()" method
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
361 that the sprites call when they want to belong or remove themselves from
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
362 the group. The add_internal() and remove_internal() have a single argument
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
363 which is a sprite. The only other requirement for the Group classes is they
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
364 have a dummy attribute named "_spritegroup". It doesn't matter what the value
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
365 is, as long as the attribute is present. The Sprite classes can look for this
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
366 attribute to determine the difference between a "group" and any ordinary python
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
367 container. (This is important, because several sprite methods can take an
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
368 argument of a single group, or a sequence of groups. Since they both look
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
369 similar, this is the most flexible way to "see" the difference.)</p>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
370
363
a5aeb6f96394 tuned sprites a little
pygame
parents: 315
diff changeset
371 <p>You should through the code for the sprite module. While
284
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
372 the code is a bit "tuned", it's got enough comments to help you follow along.
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
373 There's even a todo section in the source if you feel like contributing.</p>
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
374
4b2ef5e549d3 sprite intro cleanups
pygame
parents:
diff changeset
375 </body></html>