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
2010-02-23 05:34:59
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
2010-02-23 05:47:56
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
2010-02-23 07:51:03
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
2010-02-23 15:26:01
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
2010-02-23 16:02:44
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
2010-02-23 23:02:41
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
2010-02-23 08:42:26
I looked in there but couldn't find which class file that the collision actually took place...
DMan
2010-02-23 23:53:14
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
2010-02-23 17:48:49