Dominic K
Dominic K

Reputation: 7085

Tile based collision in XNA

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'?

Upvotes: 5

Views: 7425

Answers (4)

Eric Harms
Eric Harms

Reputation: 569

Rectangles have a intersects method. If your player is centered and you know the coordinates, loop through the other texture2ds and check for an intersection before scrolling the map.

Upvotes: 0

smack0007
smack0007

Reputation: 11356

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.

Upvotes: 1

Paolo Tedesco
Paolo Tedesco

Reputation: 57262

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

Upvotes: 0

Brian Rasmussen
Brian Rasmussen

Reputation: 116481

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.

Upvotes: 5

Related Questions