Surface Detection in 2d Game?

Posted by GamiShini on Stack Overflow See other posts from Stack Overflow or by GamiShini
Published on 2010-06-04T11:18:02Z Indexed on 2010/06/07 4:12 UTC
Read the original article Hit count: 277

Filed under:
|
|
|

I'm working on a 2D Platform game, and I was wondering what's the best (performance-wise) way to implement Surface (Collision) Detection.

So far I'm thinking of constructing a list of level objects constructed of a list of lines, and I draw tiles along the lines.

( http://img375.imageshack.us/img375/1704/lines.png ).

I'm thinking every object holds the ID of the surface that he walks on, in order to easily manipulate his y position while walking up/downhill.

Something like this:

//Player/MovableObject class
MoveLeft()
{
    this.Position.Y = Helper.GetSurfaceById(this.SurfaceId).GetYWhenXIs(this.Position.X)
}

So the logic I use to detect "droping/walking on surface" is a simple point (player's lower legs)-touches-line (surface) check (with some safety approximation - let`s say 1-2 pixels over the line).

Is this approach OK? I`ve been having difficulty trying to find reading material for this problem, so feel free to drop links/advice.

© Stack Overflow or respective owner

Related posts about game-development

Related posts about XNA