Maps that use tilesets, like super nintendo/nes RPG's store the tile ID
number for each tile. Map is a 2d array of ID's. This takes almost no
memory, since if you have 100 tiles, with 2 types of tiles, you end up with
2 images loaded. vs redundant Sprites on every square.

source_x = tile_width * ID
source_rect = Rect( source_x, 0, tile_width, tile_height )

The pinman tutorials use tiles as well, just not in a grid. At game start,
it creates a rectangle filled Sprite using Color. Then in the loop, it draws
the pre-rendered surface.
This is because re-creating a new surface, every loop, is slow. It has some
SpriteGroup examples that can make the other tut easier to read.

http://www.sacredchao.net/~piman/writing/sprite-tutorial.shtml

And probably overkill for now, but sometime you'll want NumPy. Reading
'quick intro' section is enough. Good page for a quickref to numpy.
http://www.scipy.org/Tentative_NumPy_Tutorial

On Tue, May 18, 2010 at 8:12 PM, Alex Hall <mehg...@gmail.com> wrote:

> 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.ew...@canterbury.ac.nz> 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)
> mehg...@gmail.com; http://www.facebook.com/mehgcap
>



-- 
Jake

Reply via email to