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

Re: [pygame] question about Rect objects



Okay, so to sprite or not to sprite... More reading. In the meantime,
do you have a place where I can find an example of drawing a grid of
Rects? Also, I would still like to put a rect into a boardSquare
object (an object I have defined) so I can call something like
board[i][j].Rect.changeColor(red) where changeColor is a method I
implement. Is this not possible / a huge waste of resources? Again, I
come with no prior experience or reference for anything like this.
Thanks for answering my newbie questions. :)

On 5/18/10, Greg Ewing <greg.ewing@xxxxxxxxxxxxxxxx> wrote:
> Alex Hall wrote:
>> Can Pygame detect
>> where on the grid that is with some sort of onImageClick type method,
>> or do I have to track coordinates?
>
> Just track coordinates. For a regular grid, it's very easy. If the
> user clicks at (x, y) and the size of your grid cell is (w, h), then
> the coordinates of the clicked cell are (x // w, y // h).
>
>> Looks like I have to do a lot more reading on sprites.
>
> I wouldn't bother with sprites. Just loop over your grid coordinates,
> calculate the pixel coordinates of the corresponding rect for each
> cell, and fill it with the appropriate colour.
>
>> maybe define a
>> blue, red, and white rect
>
> Rects don't have colours, they just hold coordinates. You only need
> one rect. The colour is specified when you make the call to draw it.
>
> --
> Greg
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap