Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

pygame.Rect question

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


scott.siegler at gmail

Apr 8, 2012, 4:58 PM

Post #1 of 4 (146 views)
Permalink
pygame.Rect question

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
--
http://mail.python.org/mailman/listinfo/python-list


d at davea

Apr 8, 2012, 5:29 PM

Post #2 of 4 (143 views)
Permalink
Re: pygame.Rect question [In reply to]

On 04/08/2012 07:58 PM, Scott Siegler wrote:
> 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

I don't know about pygame, but almost everywhere in the standard
library, ranges are closed at the begin and open at the end. For
example, if you have range(30, 50), there are 20 items, numbered 30
through 49. I expect the same will be true for rect.right() and
rect.bottom().



--

DaveA

--
http://mail.python.org/mailman/listinfo/python-list


pekkakarj at gmail

Apr 9, 2012, 1:24 AM

Post #3 of 4 (139 views)
Permalink
Re: pygame.Rect question [In reply to]

On Mon, Apr 9, 2012 at 3:29 AM, Dave Angel <d [at] davea> wrote:
> I don't know about pygame, but almost everywhere in the standard
> library, ranges are closed at the begin and open at the end.  For
> example, if you have range(30, 50), there are 20 items, numbered 30
> through 49.  I expect the same will be true for rect.right() and
> rect.bottom().

Your expectation is correct. I'll just point out the part in the
Pygame docs that spells this out.

http://www.pygame.org/docs/ref/rect.html

"The area covered by a Rect does not include the right- and
bottom-most edge of pixels. If one Rect's bottom border is another
Rect's top border (i.e., rect1.bottom=rect2.top), the two meet exactly
on the screen but do not overlap, and rect1.colliderect(rect2) returns
false."

Pekka
--
http://mail.python.org/mailman/listinfo/python-list


ppearson at nowhere

Apr 9, 2012, 8:41 AM

Post #4 of 4 (136 views)
Permalink
Re: pygame.Rect question [In reply to]

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.

--
To email me, substitute nowhere->spamcop, invalid->net.
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.