[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Question regarding a Rect()-object



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.