0

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.

4
  • There are two issues involved here, collision detection and collision response. In terms of collision detection, there are hundreds and hundreds of articles on google about rectangle to rectangle collision detection. Once a collision has been detected though, how do you want to respond to it? One common method would be to move your player back to the last place where it wasn't colliding with anything.. Commented Aug 25, 2011 at 7:59
  • possible duplicate of Collision detection with tiles Commented Aug 25, 2011 at 8:00
  • 3
    You've asked this earlier, if you don't like the answer given comment on it, and maybe rephrase your question so you're clearer, you shouldn't create a new question. Commented Aug 25, 2011 at 8:01
  • i would put the tiles in a 2D array and then have an attribute inside the player that references to its current position. Then your collision detection would be something like Player.Position == tileArray[Player.Position.X, Player.Position.Y] Commented Aug 25, 2011 at 10:12

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.