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

Re: [pygame] updating rects



enrike wrote:
I hav two big rects that i need to update. But the are overlapping one
each other.
I would like to update rect1 and then the non-overlaping part of rect2.
How could i do this using the rect intersecting functions of pygame?  or
is it the update function clever enough to deal with this on its own? (i
suspect it is)
Currently the only real way to do this is with Rect.union. This will give you an entire rectangle with no overlap, but will include extra areas around the corners. This may seem a bit wasteful, but so far hasn't been the bottleneck for any performance issues.

I am drawing the external lines of a rectangle (i am using draw.rect but i could also use draw.lines i guess). Instead of updating the whole
It is not hard to draw the box with draw.lines, but you will get a single rectangle. If you are needing the specific edges you'll need to draw each edge at a time.

r = myrectangle
edges = (r.topleft, t.topright), (r.topright, r.bottomright), ...
dirtyrects = []
for e in edges:
pygame.draw(screen, color, e[0], e[1], 1)

or something like that, i'm trying to remember all this right before going to bed. Seeya.