[SDL] Pixel Perfect Sprite Collisions
pvl at uh.cz
Mon Mar 24 08:32:01 PST 2003
On Mon, Mar 24, 2003 at 11:51:54AM -0000, James Pickard wrote:
> I have read examples of other sprite collisions using pixel perfect
> detection, and I understand that they access the pixel data of the
> overlap of the image RECTs and loop through every pixel in the
> overlapping rectangle, comparing pixel data each time to check for 2
> non-alpha pixels. I do not know how to access the pixel data of the
> image files, or in this case I suppose it would be the relevent
> surface. I do not know how to tell whether the pixel being accessed
> has the same RGB values as the alpha channel for that surface.
How about using a separate collision bitmap for every sprite that would
have one bit per sprite's pixel, telling if this pixel collides or not?
I don't think it's good to create an artificial dependency between
whether a pixel is drawn/transparent and whether it collides with nearby
objects. Transparency and collisions are two separate things - you can
easily imagine sprites that have parts that are not transparent and
still do not collide (various kinds of smoke, halo etc.).
Sure, you could resolve such cases by adopting a policy that either a
sprite collides or it does not - then you can have a colliding spaceship
sprite and a non-colliding engine smoke sprite, combining them during
blitting. However, I'm not sure if this doesn't bring about more
complexity than it solves.
More information about the SDL