[SDL] Pixel perfect collision detection

Bill Kendrick nbs at sonic.net
Sun Jun 26 23:50:47 PDT 2005


On Mon, Jun 27, 2005 at 11:21:43AM +0530, Windows-Games wrote:
> Ok, I am with another question on the same line.
> 
> I wanted a ball to move in a maze, controled my mouse scrolling speed.
> 
> I let the ball collide and then find how the ball should react to collison.
> ( It has to bounce back once it hits a wall or other balls)
> 
> When the ball moves so fast, (on a system with lower frame rates)
> the ball moves past the walls, before I get a chance to check collision. 
> 
> What is the standard practice in these situation? 

Check for collision at every (reasonable, at least) point between where it
is in frame N and where it is in frame N + 1.

In other words, if you can only draw it at 10fps, but in doing so that
causes the ball to go through the wall, move the ball incrementally a
number of times BETWEEN frames.

Remember, if you're doing something insanely complicated (like I'm guessing
Liquid War does, since it's so free-form), you can do bounding box checks
as an optimization.  Then, if there's a CHANCE that there might be
a pixel collision, do the more CPU-intensive pixel-perfect test.
Otherwise... nothin' to see here.  Keep moving.

-bill!




More information about the SDL mailing list