Rich Porter
Rich Porter

Reputation: 213

Collision detection between my player and the tiles(background). XNA

So, I want to check collision between my player and the tiles. The tile isn't one big object, but the tile is 32*32 pixels size and there are like 11 of them, used as floor so the player will be able to walk on it. My question is, how am I going to detect it? Pixel Collision doesn't sound very effective. If I should use rectangle collision, I'd like to get an explanation how am I going to implement it into my code.

Thanks alot.

Upvotes: 0

Views: 1151

Answers (1)

Stephen Tierney
Stephen Tierney

Reputation: 355

I suggest downloading and learning the Platformer Starter Kit, developed by Microsoft.

Download: Starter Kit Download

MSDN discussion Starter Kit Discussion

The simplest explanation for their solution is that tiles are kept in a 2D array to represent the world. When the player's Update() function is called a HandleCollisions() function is called that loops through a subset of the tile array to look for possible collisions. For every possible collision with the player the depth of intersection with the player bounds and the tile, the players position is adjusted to bring it out of the tile.

Upvotes: 1

Related Questions