views:

705

answers:

3

I have drawn tiles in my XNA game and loaded my character. My character, however, doesn't move- the map does, which gives it the illusion of movement. Now I am wondering how to actually test against them for collision. I mean, where does the collision code go and how do I make all tiles represent 'one big thing'?

A: 

There's a tutorial on pixel based collision detection on XNA Creator's club. You'll need to figure out what objects you want to do collision detection on. I guess you want the character to move across the tiled background, so you don't want to check for collision between your character and the background. Instead you should make any obstacle s sprites and do collision detection on those.

Brian Rasmussen
That I know, but I don't know how to test collision for those obstacles as they are tiles that are placed by a for loop.
DMan
I am not sure I follow. It doesn't matter how you draw your textures. You need to identify the textures for which you want to do collision detection and apply the detection as described in the included .htm file in the sample.
Brian Rasmussen
Well, since I draw each texture many times, don't I have to apply collision more than once? If so, where would I do it- during my drawing code>
DMan
My guess is that you have textures that represent the background. I assume you will draw those multiple times and that you do not want to detect collisions with those. If you have other obstacles you want to check for collision, you have to check each of these.
Brian Rasmussen
Oh, I guess my approach may have been wrong then. I was trying to draw textures that didn't represent the background, but the obstacles instead.
DMan
A: 

You could have a look at the Platformer Starter Kit, it shows how to organize tiles in a map and check for collisions.

Paolo Tedesco
I looked in there but couldn't find which class file that the collision actually took place...
DMan
A: 

You might have a look at Nick Gravelyn's Tile Engine Tutorials, it goes through the whole process of creating a tile engine. There's a link here to see all the tutorials on YouTube.

smack0007