[Tutor] Question about sprites

Paul Sidorsky paulsid@shaw.ca
Fri, 14 Jun 2002 15:34:52 -0600


James M Lang wrote:

> I heard from a friend that in the videogame world that sprites are 
> programmed by telling the computer or videogame console where each 
> pixel or dot was. That sounds kinda tedious. Couldn't you just load 
> a picture? Is that possible?

I think perhaps some of the details might have got lost somewhere in the
description.  Sprites generally do indeed work by drawing a picture as
you suggested.

For simple games you just keep one coordinate in memory and draw the
entire picture at that point.  This coordinate is called the "hotspot". 
Regardless of whether the picture is a giant space ship or a tiny
projectile, you only need one coordinate for it.  The hotspot can be put
anywhere within the picture.  Popular choices are the top left (because
it's the easiest to manage) and the centre (because you can do simple
radius-based collision detection).

Fancier systems might define the hotspot differently for each sprite or
might have multiple hotspots for each sprite to allow for fancier
collision algorithms.  For example you might make each pixel on the edge
of the sprite (e.g. the spaceship) a hotspot; this would perfectly
define the boundary of the ship so your collisions would be very
accurate.  Of course this does take more computing power and does get
more tedious as you suggested.

If you're interested in doing stuff with sprites in Python, pygame now
comes with a really cool sprite module which will manage lots of things
for you.  The sprite module is written in Python itself so you can see
how it manages everything too - check sprite.py in your site-packages
directory.

BTW I'm not in the videogame industry by any means, I'm just a hobbyist
game programmer.  "Real game programmers" probably do things much more
sophisticatedly, especially nowadays.

-- 
======================================================================
Paul Sidorsky                                          Calgary, Canada
paulsid@shaw.ca                        http://members.shaw.ca/paulsid/