[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Question regarding a Rect()-object
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Question regarding a Rect()-object
- From: "Rikard Bosnjakovic" <rikard.bosnjakovic@xxxxxxxxx>
- Date: Thu, 29 Jun 2006 04:49:04 +0200
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Wed, 28 Jun 2006 22:49:13 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=LI0vpcPQDn3ic6Wbnf3YpArcwTf5TEYlSWTIe1xOOljXgVpdzfE61u+GIkSiITwJBOQNeQLeEny26HxhrIYbZQQUYAsR21m5NC+wsVnm0E0VdK7SPiThaGY1nGXrniQqPEYC3Qojvp7eeB04CDEVRaTVTSHfAz6YgppRpV3W0IU=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
I've just learned how to use a Rect() and find them extremely useful.
However, I just stumbled into a problem that confused me a lot. It's
about defining a rect's bounds without using width and height.
Consider this:
a = Rect(0, 0, 0, 0)
a.x, a.y = 10, 10
a.height, a.width
(0, 0)
So far so good, a rect at (10,10) with no width, height. If the width
and height is set, the rect's right and bottom-property are also set
correctly:
a.width = a.height = 50
a
<rect(10, 10, 50, 50)>
a.right, a.bottom
(60, 60)
What I currently want to do is to ignore setting width/height, but set
x/y/right/bottom instead. However, doing that results in this:
a.x = a.y = 20
a.right, a.bottom = 100, 100
a.x, a.y, a.height, a.width
(100, 100, 0, 0)
Since width/height is not defined, x and y are moved to left and
bottom respectively. While thinking about it, it's surely logical in
one way, but not in the way I'm trying to do.
So, to conclude: is there a way to define a Rect() by using the
bounding points instead of filling in height/width (letting the
Rect-object do it by itself), or am I forced to calculate width/height
on my own?
The reason I'm asking is because in my game, a lot of surfaces relies
on other surfaces' (bounding box-)positions, and when creating a new
surface, it's bounding box is much more of importance than its
width/height.
--
Rikard.