3
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>
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>
9
<img src=../pygame_tiny.gif border=0 width=200 height=60></a><br>
10
<b>pygame documentation</b>
11
</td><td bgcolor=6aee28 align=center valign=top width=100%>
14
<a href=http://www.pygame.org>Home</a> ||
15
<a href=../index.html>Help Contents</a> ||
18
|| <a href=pygame.html>pygame</a> ||
19
<a href=pygame_cdrom.html>cdrom</a> ||
20
<a href=pygame_constants.html>constants</a> ||
21
<a href=pygame_display.html>display</a> ||
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> ||
25
<a href=pygame_image.html>image</a> ||
26
<a href=pygame_joystick.html>joystick</a> ||
27
<a href=pygame_key.html>key</a> ||
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> ||
31
<a href=pygame_movie.html>movie</a> ||
32
<a href=pygame_surfarray.html>surfarray</a> ||
33
<a href=pygame_time.html>time</a> ||
34
<a href=pygame_transform.html>transform</a> ||<br>
35
<br>|| <a href=CD.html>CD</a> ||
36
<a href=Channel.html>Channel</a> ||
37
<a href=Clock.html>Clock</a> ||
38
<a href=Font.html>Font</a> ||
39
<a href=Joystick.html>Joystick</a> ||
40
<a href=Movie.html>Movie</a> ||<br>
41
|| <a href=Rect.html>Rect</a> ||
42
<a href=Sound.html>Sound</a> ||
43
<a href=Surface.html>Surface</a> ||<br>
44
<br>|| <a href=pygame_cursors.html>cursors</a> ||
45
<a href=pygame_sprite.html>sprite</a> ||
46
<a href=pygame_version.html>version</a> ||<br>
49
</td></tr></table></td></tr></table>
51
<h2 align=center>Rect</h2>
52
The rectangle object is a useful object
53
representing a rectangle area. Rectangles are
54
created from the <a href=pygame.html#Rect>pygame.Rect()</a> function. This routine
55
is also in the locals module, so importing the locals
56
into your namespace allows you to just use <a href=pygame.html#Rect>Rect()</a>.
58
Rect contains helpful methods, as well as a list of
60
top, bottom, left, right, topleft, topright,
61
bottomleft, bottomright, size, width, height,
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)
68
The rectstyle arguments used frequently with the
69
Rect object (and elsewhere in pygame) is one of
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,
82
<tr><td><a href=#clamp>clamp</a></td><td> -
83
move rectangle inside another</td></tr>
86
<tr><td><a href=#clamp_ip>clamp_ip</a></td><td> -
87
moves the rectangle inside another</td></tr>
90
<tr><td><a href=#clip>clip</a></td><td> -
91
rectangle cropped inside another</td></tr>
94
<tr><td><a href=#collidelist>collidelist</a></td><td> -
95
find overlapping rectangle</td></tr>
98
<tr><td><a href=#collidelistall>collidelistall</a></td><td> -
99
find all overlapping rectangles</td></tr>
102
<tr><td><a href=#collidepoint>collidepoint</a></td><td> -
103
point inside rectangle</td></tr>
106
<tr><td><a href=#colliderect>colliderect</a></td><td> -
107
check overlapping rectangles</td></tr>
110
<tr><td><a href=#contains>contains</a></td><td> -
111
check if rectangle fully inside another</td></tr>
114
<tr><td><a href=#inflate>inflate</a></td><td> -
115
new rectangle with size changed</td></tr>
118
<tr><td><a href=#inflate_ip>inflate_ip</a></td><td> -
119
changes the Rect size</td></tr>
122
<tr><td><a href=#move>move</a></td><td> -
123
new rectangle with position changed</td></tr>
126
<tr><td><a href=#move_ip>move_ip</a></td><td> -
127
move the Rect by the given offset</td></tr>
130
<tr><td><a href=#normalize>normalize</a></td><td> -
131
corrects negative sizes</td></tr>
134
<tr><td><a href=#union>union</a></td><td> -
135
makes new rectangle covering both inputs</td></tr>
138
<tr><td><a href=#union_ip>union_ip</a></td><td> -
139
rectangle covering both input</td></tr>
142
<tr><td><a href=#unionall>unionall</a></td><td> -
143
rectangle covering all inputs</td></tr>
146
<tr><td><a href=#unionall_ip>unionall_ip</a></td><td> -
147
rectangle covering all inputs</td></tr>
154
<a name=clamp><font size=+2><b>clamp
155
</b></font><br><font size=+1><tt>
156
Rect.clamp(rectstyle) -> Rect
158
Returns a new rectangle that is moved to be
159
completely inside the argument rectangle. If the base
160
rectangle is too large for the argument rectangle in
161
an axis, it will be centered on that axis.
164
<a name=clamp_ip><font size=+2><b>clamp_ip
165
</b></font><br><font size=+1><tt>
166
Rect.clamp_ip(rectstyle) -> None
169
completely inside the argument rectangle. If the given
170
rectangle is too large for the argument rectangle in
171
an axis, it will be centered on that axis.
174
<a name=clip><font size=+2><b>clip
175
</b></font><br><font size=+1><tt>
176
Rect.clip(rectstyle) -> Rect
178
Returns a new rectangle that is the given
179
rectangle cropped to the inside of the base
180
rectangle. If the two rectangles do not overlap to
181
begin with, you will get a rectangle with 0 size.
184
<a name=collidelist><font size=+2><b>collidelist
185
</b></font><br><font size=+1><tt>
186
Rect.collidelist(rectstyle list) -> int index
188
Returns the index of the first rectangle in the
189
list to overlap the base rectangle. Once an
190
overlap is found, this will stop checking the
191
remaining list. If no overlap is found, it will
195
<a name=collidelistall><font size=+2><b>collidelistall
196
</b></font><br><font size=+1><tt>
197
Rect.collidelistall(rectstyle list) -> int index
199
Returns a list of the indexes that contain
200
rectangles overlapping the base rectangle. If no
201
overlap is found, it will return an empty
205
<a name=collidepoint><font size=+2><b>collidepoint
206
</b></font><br><font size=+1><tt>
207
Rect.collidepoint(x, y) -> bool
209
Returns true if the given point position is inside
210
the rectangle. If a point is on the border, it is
214
<a name=colliderect><font size=+2><b>colliderect
215
</b></font><br><font size=+1><tt>
216
Rect.colliderect(rectstyle) -> bool
218
Returns true if any area of the two rectangles
222
<a name=contains><font size=+2><b>contains
223
</b></font><br><font size=+1><tt>
224
Rect.contains(rectstyle) -> bool
226
Returns true when the given rectangle is entirely
227
inside the base rectangle.
230
<a name=inflate><font size=+2><b>inflate
231
</b></font><br><font size=+1><tt>
232
Rect.inflate(x, y) -> Rect
234
Returns a new rectangle which has the sizes
235
changed by the given amounts. The rectangle
236
shrinks and expands around the rectangle's center.
237
Negative values will shrink the rectangle.
240
<a name=inflate_ip><font size=+2><b>inflate_ip
241
</b></font><br><font size=+1><tt>
242
Rect.inflate_ip(x, y) -> None
244
Changes the Rect by the given amounts. The rectangle
245
shrinks and expands around the rectangle's center.
246
Negative values will shrink the rectangle.
249
<a name=move><font size=+2><b>move
250
</b></font><br><font size=+1><tt>
251
Rect.move(x, y) -> Rect
253
Returns a new rectangle which is the base
254
rectangle moved by the given amount.
257
<a name=move_ip><font size=+2><b>move_ip
258
</b></font><br><font size=+1><tt>
259
Rect.move_ip(x, y) -> None
261
Moves the rectangle which by the given amount.
264
<a name=normalize><font size=+2><b>normalize
265
</b></font><br><font size=+1><tt>
266
Rect.normalize() -> None
268
If the rectangle has a a negative size in width or
269
height, this will flip that axis so the sizes are
270
positive, and the rectangle remains in the same
274
<a name=union><font size=+2><b>union
275
</b></font><br><font size=+1><tt>
276
Rect.union(rectstyle) -> Rect
278
Creates a new Rect to completely cover the
279
given input. There may be area inside the new
280
Rect that is not covered by either input.
283
<a name=union_ip><font size=+2><b>union_ip
284
</b></font><br><font size=+1><tt>
285
Rect.union_ip(rectstyle) -> None
287
Resizes the Rect to completely cover the
288
given input. There may be area inside the new
289
dimensions that is not covered by either input.
292
<a name=unionall><font size=+2><b>unionall
293
</b></font><br><font size=+1><tt>
294
Rect.unionall(sequence_of_rectstyles) -> Rect
296
Returns a new rectangle that completely covers all the
297
given inputs. There may be area inside the new
298
rectangle that is not covered by the inputs.
301
<a name=unionall_ip><font size=+2><b>unionall_ip
302
</b></font><br><font size=+1><tt>
303
Rect.unionall_ip(sequence_of_rectstyles) -> None
305
Returns a new rectangle that completely covers all the
306
given inputs. There may be area inside the new
307
rectangle that is not covered by the inputs.