pygame.Rect question

S

Scott Siegler

Hello,

I am new to Python and began using pygame to start some game programming. I was hoping someone could help me out with something that seems simple but is really confusing me.

I am creating a rect and then using the attributes of the rect to set the size and location.

I set rect.left to 30, rect.top to 30 and rect.width = 20

This works fine. However, when looking at rect.right() it shows that it is equal to 50. I suppose this is equal to 30+20. However, since the first pixel is on location 30, wouldn't the 20th pixel be on 49 (not 50)?

Am I missing something here? It is really confusing me when I am doing some collision algorithms.

Any help?

Thanks,
Scott
 
P

Peter Pearson

On Sun, 8 Apr 2012 16:58:01 -0700 (PDT), Scott Siegler wrote:
[snip]
I set rect.left to 30, rect.top to 30 and rect.width = 20

This works fine. However, when looking at rect.right() it
shows that it is equal to 50. I suppose this is equal to
30+20. However, since the first pixel is on location 30,
wouldn't the 20th pixel be on 49 (not 50)?

Am I missing something here? It is really confusing me
when I am doing some collision algorithms.

I'm not a pygame expert, but . . . it would be consistent
with Python's conventions for ranges of indices if
rect.right() were the first pixel *outside* the rectangle.
Of course, one would expect rect.bottom() to work similarly.

If this is the right explanation, it will be useful to
picture indices pointing between pixels, rather than at
pixels.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top