pygame.Rect question

Discussion in 'Python' started by Scott Siegler, Apr 9, 2012.

  1. 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, 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?

    Scott Siegler, Apr 9, 2012
    1. Advertisements

  2. On Sun, 8 Apr 2012 16:58:01 -0700 (PDT), Scott Siegler wrote:
    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
    Peter Pearson, Apr 9, 2012
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.