|
16
|
1 <html>
|
|
|
2 <title>Rect</title>
|
|
235
|
3 <body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>
|
|
|
4
|
|
16
|
5
|
|
235
|
6 <table cellspacing=3 width=100%><tr><td bgcolor=#00000>
|
|
|
7 <table width=100%><tr><td bgcolor=c2fc20 align=center>
|
|
|
8 <a href=http://www.pygame.org>
|
|
250
|
9 <img src=../pygame_tiny.gif border=0 width=200 height=60></a><br>
|
|
235
|
10 <b>pygame documentation</b>
|
|
|
11 </td><td bgcolor=6aee28 align=center valign=top width=100%>
|
|
16
|
12
|
|
|
13 ||
|
|
178
|
14 <a href=http://www.pygame.org>Home</a> ||
|
|
16
|
15 <a href=../index.html>Help Contents</a> ||
|
|
|
16 <br> <br>
|
|
|
17
|
|
384
|
18 || <a href=pygame.html>pygame</a> ||
|
|
265
|
19 <a href=pygame_cdrom.html>cdrom</a> ||
|
|
|
20 <a href=pygame_constants.html>constants</a> ||
|
|
|
21 <a href=pygame_display.html>display</a> ||
|
|
384
|
22 <a href=pygame_draw.html>draw</a> ||
|
|
|
23 <a href=pygame_event.html>event</a> ||<br>
|
|
|
24 || <a href=pygame_font.html>font</a> ||
|
|
265
|
25 <a href=pygame_image.html>image</a> ||
|
|
|
26 <a href=pygame_joystick.html>joystick</a> ||
|
|
|
27 <a href=pygame_key.html>key</a> ||
|
|
384
|
28 <a href=pygame_mixer.html>mixer</a> ||
|
|
|
29 <a href=pygame_mixer_music.html>mixer_music</a> ||<br>
|
|
|
30 || <a href=pygame_mouse.html>mouse</a> ||
|
|
265
|
31 <a href=pygame_movie.html>movie</a> ||
|
|
370
|
32 <a href=pygame_sndarray.html>sndarray</a> ||
|
|
265
|
33 <a href=pygame_surfarray.html>surfarray</a> ||
|
|
384
|
34 <a href=pygame_time.html>time</a> ||
|
|
|
35 <a href=pygame_transform.html>transform</a> ||<br>
|
|
265
|
36 <br>|| <a href=CD.html>CD</a> ||
|
|
16
|
37 <a href=Channel.html>Channel</a> ||
|
|
277
|
38 <a href=Clock.html>Clock</a> ||
|
|
16
|
39 <a href=Font.html>Font</a> ||
|
|
|
40 <a href=Joystick.html>Joystick</a> ||
|
|
277
|
41 <a href=Movie.html>Movie</a> ||<br>
|
|
|
42 || <a href=Rect.html>Rect</a> ||
|
|
|
43 <a href=Sound.html>Sound</a> ||
|
|
265
|
44 <a href=Surface.html>Surface</a> ||<br>
|
|
299
|
45 <br>|| <a href=pygame_cursors.html>cursors</a> ||
|
|
375
|
46 <a href=pygame_sprite.html>sprite</a> ||<br>
|
|
16
|
47
|
|
|
48
|
|
235
|
49 </td></tr></table></td></tr></table>
|
|
16
|
50 <br>
|
|
|
51 <h2 align=center>Rect</h2>
|
|
|
52 The rectangle object is a useful object
|
|
20
|
53 representing a rectangle area. Rectangles are
|
|
151
|
54 created from the <a href=pygame.html#Rect>pygame.Rect()</a> function. This routine
|
|
20
|
55 is also in the locals module, so importing the locals
|
|
151
|
56 into your namespace allows you to just use <a href=pygame.html#Rect>Rect()</a>.
|
|
|
57 <br> <br>
|
|
20
|
58 Rect contains helpful methods, as well as a list of
|
|
|
59 modifiable members:
|
|
16
|
60 top, bottom, left, right, topleft, topright,
|
|
|
61 bottomleft, bottomright, size, width, height,
|
|
182
|
62 center, centerx, centery, midleft, midright, midtop,
|
|
|
63 midbottom. When changing thesemembers, the rectangle
|
|
|
64 will be moved to the given assignment. (except when
|
|
|
65 changing the size, width, or height member, which will
|
|
|
66 resize the rectangle from the topleft corner)
|
|
151
|
67 <br> <br>
|
|
16
|
68 The rectstyle arguments used frequently with the
|
|
29
|
69 Rect object (and elsewhere in pygame) is one of
|
|
16
|
70 the following things. First, an actual Rect
|
|
|
71 object. Second, a sequence of [xpos, ypos, width,
|
|
|
72 height]. Lastly, a pair of sequences, representing
|
|
|
73 the position and size [[xpos, ypos], [width,
|
|
|
74 height]]. Also, if a method takes a rectstyle
|
|
|
75 argument as its only argument, you can simply pass
|
|
|
76 four arguments representing xpos, ypos, width,
|
|
364
|
77 height. A rectstyle argument can also be _any_ python
|
|
|
78 object with an attribute named 'rect'.
|
|
16
|
79
|
|
|
80 <hr>
|
|
|
81
|
|
|
82 <table>
|
|
|
83 <tr><td><a href=#clamp>clamp</a></td><td> -
|
|
|
84 move rectangle inside another</td></tr>
|
|
|
85
|
|
|
86
|
|
255
|
87 <tr><td><a href=#clamp_ip>clamp_ip</a></td><td> -
|
|
274
|
88 moves the rectangle inside another</td></tr>
|
|
255
|
89
|
|
|
90
|
|
16
|
91 <tr><td><a href=#clip>clip</a></td><td> -
|
|
|
92 rectangle cropped inside another</td></tr>
|
|
|
93
|
|
|
94
|
|
362
|
95 <tr><td><a href=#collidedict>collidedict</a></td><td> -
|
|
|
96 find overlapping rectangle in a dictionary</td></tr>
|
|
|
97
|
|
|
98
|
|
|
99 <tr><td><a href=#collidedictall>collidedictall</a></td><td> -
|
|
|
100 find all overlapping rectangles</td></tr>
|
|
|
101
|
|
|
102
|
|
42
|
103 <tr><td><a href=#collidelist>collidelist</a></td><td> -
|
|
|
104 find overlapping rectangle</td></tr>
|
|
|
105
|
|
|
106
|
|
|
107 <tr><td><a href=#collidelistall>collidelistall</a></td><td> -
|
|
|
108 find all overlapping rectangles</td></tr>
|
|
|
109
|
|
|
110
|
|
16
|
111 <tr><td><a href=#collidepoint>collidepoint</a></td><td> -
|
|
|
112 point inside rectangle</td></tr>
|
|
|
113
|
|
|
114
|
|
|
115 <tr><td><a href=#colliderect>colliderect</a></td><td> -
|
|
|
116 check overlapping rectangles</td></tr>
|
|
|
117
|
|
|
118
|
|
|
119 <tr><td><a href=#contains>contains</a></td><td> -
|
|
|
120 check if rectangle fully inside another</td></tr>
|
|
|
121
|
|
|
122
|
|
|
123 <tr><td><a href=#inflate>inflate</a></td><td> -
|
|
|
124 new rectangle with size changed</td></tr>
|
|
|
125
|
|
|
126
|
|
204
|
127 <tr><td><a href=#inflate_ip>inflate_ip</a></td><td> -
|
|
|
128 changes the Rect size</td></tr>
|
|
|
129
|
|
|
130
|
|
16
|
131 <tr><td><a href=#move>move</a></td><td> -
|
|
|
132 new rectangle with position changed</td></tr>
|
|
|
133
|
|
|
134
|
|
204
|
135 <tr><td><a href=#move_ip>move_ip</a></td><td> -
|
|
|
136 move the Rect by the given offset</td></tr>
|
|
|
137
|
|
|
138
|
|
16
|
139 <tr><td><a href=#normalize>normalize</a></td><td> -
|
|
|
140 corrects negative sizes</td></tr>
|
|
|
141
|
|
|
142
|
|
|
143 <tr><td><a href=#union>union</a></td><td> -
|
|
204
|
144 makes new rectangle covering both inputs</td></tr>
|
|
|
145
|
|
|
146
|
|
|
147 <tr><td><a href=#union_ip>union_ip</a></td><td> -
|
|
16
|
148 rectangle covering both input</td></tr>
|
|
|
149
|
|
|
150
|
|
182
|
151 <tr><td><a href=#unionall>unionall</a></td><td> -
|
|
|
152 rectangle covering all inputs</td></tr>
|
|
|
153
|
|
|
154
|
|
204
|
155 <tr><td><a href=#unionall_ip>unionall_ip</a></td><td> -
|
|
|
156 rectangle covering all inputs</td></tr>
|
|
|
157
|
|
|
158
|
|
16
|
159 </table>
|
|
|
160
|
|
|
161 <hr>
|
|
|
162
|
|
|
163 <a name=clamp><font size=+2><b>clamp
|
|
|
164 </b></font><br><font size=+1><tt>
|
|
|
165 Rect.clamp(rectstyle) -> Rect
|
|
|
166 </tt></font><ul>
|
|
|
167 Returns a new rectangle that is moved to be
|
|
310
|
168 completely inside the argument rectangle. If the base
|
|
|
169 rectangle is too large for the argument rectangle in
|
|
16
|
170 an axis, it will be centered on that axis.
|
|
|
171 </ul><br> <br>
|
|
|
172
|
|
255
|
173 <a name=clamp_ip><font size=+2><b>clamp_ip
|
|
|
174 </b></font><br><font size=+1><tt>
|
|
|
175 Rect.clamp_ip(rectstyle) -> None
|
|
|
176 </tt></font><ul>
|
|
|
177 Moves the Rect to be
|
|
310
|
178 completely inside the argument rectangle. If the given
|
|
|
179 rectangle is too large for the argument rectangle in
|
|
255
|
180 an axis, it will be centered on that axis.
|
|
|
181 </ul><br> <br>
|
|
|
182
|
|
16
|
183 <a name=clip><font size=+2><b>clip
|
|
|
184 </b></font><br><font size=+1><tt>
|
|
|
185 Rect.clip(rectstyle) -> Rect
|
|
|
186 </tt></font><ul>
|
|
|
187 Returns a new rectangle that is the given
|
|
|
188 rectangle cropped to the inside of the base
|
|
|
189 rectangle. If the two rectangles do not overlap to
|
|
|
190 begin with, you will get a rectangle with 0 size.
|
|
|
191 </ul><br> <br>
|
|
|
192
|
|
362
|
193 <a name=collidedict><font size=+2><b>collidedict
|
|
|
194 </b></font><br><font size=+1><tt>
|
|
|
195 Rect.collidedict(dict if rectstyle keys) -> key/value pair
|
|
|
196 </tt></font><ul>
|
|
|
197 Returns the key/value pair of the first rectangle key
|
|
|
198 in the dict that overlaps the base rectangle. Once an
|
|
|
199 overlap is found, this will stop checking the
|
|
|
200 remaining list. If no overlap is found, it will
|
|
|
201 return None.
|
|
363
|
202 <br> <br>
|
|
|
203 Remember python dictionary keys must be immutable,
|
|
|
204 Rects are not immutable, so they cannot directly be,
|
|
|
205 dictionary keys. You can convert the Rect to a tuple
|
|
384
|
206 with the tuple() builtin command.
|
|
362
|
207 </ul><br> <br>
|
|
|
208
|
|
|
209 <a name=collidedictall><font size=+2><b>collidedictall
|
|
|
210 </b></font><br><font size=+1><tt>
|
|
|
211 Rect.collidedictall(rectstyle list) -> key/val list
|
|
|
212 </tt></font><ul>
|
|
|
213 Returns a list of the indexes that contain
|
|
|
214 rectangles overlapping the base rectangle. If no
|
|
|
215 overlap is found, it will return an empty
|
|
|
216 sequence.
|
|
363
|
217 <br> <br>
|
|
|
218 Remember python dictionary keys must be immutable,
|
|
|
219 Rects are not immutable, so they cannot directly be,
|
|
|
220 dictionary keys. You can convert the Rect to a tuple
|
|
384
|
221 with the tuple() builtin command.
|
|
362
|
222 </ul><br> <br>
|
|
|
223
|
|
42
|
224 <a name=collidelist><font size=+2><b>collidelist
|
|
|
225 </b></font><br><font size=+1><tt>
|
|
|
226 Rect.collidelist(rectstyle list) -> int index
|
|
|
227 </tt></font><ul>
|
|
|
228 Returns the index of the first rectangle in the
|
|
|
229 list to overlap the base rectangle. Once an
|
|
|
230 overlap is found, this will stop checking the
|
|
|
231 remaining list. If no overlap is found, it will
|
|
|
232 return -1.
|
|
|
233 </ul><br> <br>
|
|
|
234
|
|
|
235 <a name=collidelistall><font size=+2><b>collidelistall
|
|
|
236 </b></font><br><font size=+1><tt>
|
|
362
|
237 Rect.collidelistall(rectstyle list) -> index list
|
|
42
|
238 </tt></font><ul>
|
|
|
239 Returns a list of the indexes that contain
|
|
|
240 rectangles overlapping the base rectangle. If no
|
|
|
241 overlap is found, it will return an empty
|
|
|
242 sequence.
|
|
|
243 </ul><br> <br>
|
|
|
244
|
|
16
|
245 <a name=collidepoint><font size=+2><b>collidepoint
|
|
|
246 </b></font><br><font size=+1><tt>
|
|
|
247 Rect.collidepoint(x, y) -> bool
|
|
|
248 </tt></font><ul>
|
|
|
249 Returns true if the given point position is inside
|
|
|
250 the rectangle. If a point is on the border, it is
|
|
|
251 counted as inside.
|
|
|
252 </ul><br> <br>
|
|
|
253
|
|
|
254 <a name=colliderect><font size=+2><b>colliderect
|
|
|
255 </b></font><br><font size=+1><tt>
|
|
|
256 Rect.colliderect(rectstyle) -> bool
|
|
|
257 </tt></font><ul>
|
|
|
258 Returns true if any area of the two rectangles
|
|
66
|
259 overlaps.
|
|
16
|
260 </ul><br> <br>
|
|
|
261
|
|
|
262 <a name=contains><font size=+2><b>contains
|
|
|
263 </b></font><br><font size=+1><tt>
|
|
|
264 Rect.contains(rectstyle) -> bool
|
|
|
265 </tt></font><ul>
|
|
|
266 Returns true when the given rectangle is entirely
|
|
|
267 inside the base rectangle.
|
|
|
268 </ul><br> <br>
|
|
|
269
|
|
|
270 <a name=inflate><font size=+2><b>inflate
|
|
|
271 </b></font><br><font size=+1><tt>
|
|
|
272 Rect.inflate(x, y) -> Rect
|
|
|
273 </tt></font><ul>
|
|
|
274 Returns a new rectangle which has the sizes
|
|
|
275 changed by the given amounts. The rectangle
|
|
|
276 shrinks and expands around the rectangle's center.
|
|
|
277 Negative values will shrink the rectangle.
|
|
|
278 </ul><br> <br>
|
|
|
279
|
|
204
|
280 <a name=inflate_ip><font size=+2><b>inflate_ip
|
|
|
281 </b></font><br><font size=+1><tt>
|
|
|
282 Rect.inflate_ip(x, y) -> None
|
|
|
283 </tt></font><ul>
|
|
|
284 Changes the Rect by the given amounts. The rectangle
|
|
|
285 shrinks and expands around the rectangle's center.
|
|
|
286 Negative values will shrink the rectangle.
|
|
|
287 </ul><br> <br>
|
|
|
288
|
|
16
|
289 <a name=move><font size=+2><b>move
|
|
|
290 </b></font><br><font size=+1><tt>
|
|
|
291 Rect.move(x, y) -> Rect
|
|
|
292 </tt></font><ul>
|
|
|
293 Returns a new rectangle which is the base
|
|
|
294 rectangle moved by the given amount.
|
|
|
295 </ul><br> <br>
|
|
|
296
|
|
204
|
297 <a name=move_ip><font size=+2><b>move_ip
|
|
|
298 </b></font><br><font size=+1><tt>
|
|
249
|
299 Rect.move_ip(x, y) -> None
|
|
204
|
300 </tt></font><ul>
|
|
|
301 Moves the rectangle which by the given amount.
|
|
|
302 </ul><br> <br>
|
|
|
303
|
|
16
|
304 <a name=normalize><font size=+2><b>normalize
|
|
|
305 </b></font><br><font size=+1><tt>
|
|
|
306 Rect.normalize() -> None
|
|
|
307 </tt></font><ul>
|
|
|
308 If the rectangle has a a negative size in width or
|
|
|
309 height, this will flip that axis so the sizes are
|
|
|
310 positive, and the rectangle remains in the same
|
|
|
311 place.
|
|
|
312 </ul><br> <br>
|
|
|
313
|
|
|
314 <a name=union><font size=+2><b>union
|
|
|
315 </b></font><br><font size=+1><tt>
|
|
|
316 Rect.union(rectstyle) -> Rect
|
|
|
317 </tt></font><ul>
|
|
351
|
318 Returns a new Rect to completely cover the
|
|
204
|
319 given input. There may be area inside the new
|
|
|
320 Rect that is not covered by either input.
|
|
|
321 </ul><br> <br>
|
|
|
322
|
|
|
323 <a name=union_ip><font size=+2><b>union_ip
|
|
|
324 </b></font><br><font size=+1><tt>
|
|
|
325 Rect.union_ip(rectstyle) -> None
|
|
|
326 </tt></font><ul>
|
|
|
327 Resizes the Rect to completely cover the
|
|
|
328 given input. There may be area inside the new
|
|
|
329 dimensions that is not covered by either input.
|
|
16
|
330 </ul><br> <br>
|
|
|
331
|
|
182
|
332 <a name=unionall><font size=+2><b>unionall
|
|
|
333 </b></font><br><font size=+1><tt>
|
|
|
334 Rect.unionall(sequence_of_rectstyles) -> Rect
|
|
|
335 </tt></font><ul>
|
|
|
336 Returns a new rectangle that completely covers all the
|
|
|
337 given inputs. There may be area inside the new
|
|
|
338 rectangle that is not covered by the inputs.
|
|
|
339 </ul><br> <br>
|
|
|
340
|
|
204
|
341 <a name=unionall_ip><font size=+2><b>unionall_ip
|
|
|
342 </b></font><br><font size=+1><tt>
|
|
|
343 Rect.unionall_ip(sequence_of_rectstyles) -> None
|
|
|
344 </tt></font><ul>
|
|
351
|
345 Resizes the rectangle to completely cover all the
|
|
204
|
346 given inputs. There may be area inside the new
|
|
|
347 rectangle that is not covered by the inputs.
|
|
|
348 </ul><br> <br>
|
|
|
349
|
|
16
|
350
|
|
|
351 <hr>
|
|
|
352 </body></html>
|