0
votes

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.

1
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..MattDavey
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.George Duckett
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]Olle89

1 Answers

1
votes

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.