• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# 2D tiles and XNA

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1greencrayon  Members

Posted 23 July 2007 - 10:57 PM

Hi folks. I am using C# and XNA. I have seen that a lot of 2d games use some sort of tile-based collision in platform/maze/rpg type games, and have been trying to work out how to do this but all of the examples/tutorials I have managed to find seem to go a bit deeper than I am able to understand. They often include scrolling and movement physics and all kinds of other complicated stuff and I can’t weed out the bits I need. What I want is just the collision detection and response part. I can use a 2d vector of ints representing tiles to draw my game screen, and I can put a moving character sprite onto the screen. But I cannot make it so that the character can only move in the areas I want it to. I read something about making tiles walkable/non-walkable. How would I do this? And more importantly, how do I know my character’s position in regards to the type of tile it is standing on? I would be great if anyone can give me a very simple example or point me in the direction of a tutorial that concentrates solely on the collision detection aspect of a tile-based game.

### #2Butterman  Members

Posted 24 July 2007 - 12:06 AM

If you have a second array of integers to represent the tiles, you can have them on either '1' (which will trigger a collision) or '0' (which means you can walk past the tile). So [1][1] = 1; Will make that tile collidable. Then you take the players co-ordinates and pump them into this formula,

//Find the tile that the player is on, on the X axisPlayerTileX = PlayerX / TileSize;//Find the tile that the player is on, on the Y axisPlayerTileY = PlayerY / TileSize;//If the tile is collidable, stop player movementif(array[PlayerTileY][PlayerTileX] == 1){PlayerMove = false;}

Simple. Eh?

### #3greencrayon  Members

Posted 24 July 2007 - 12:09 AM

Yes very simple, doh. Probably why I could not find any tutorials on it. For the same reason you dont see many online tutorials on how to inhale. Thanks for the help, that is exactly what I wanted.

### #4Butterman  Members

Posted 24 July 2007 - 12:13 AM

Well actually, if you go here:

http://www.xnaresources.com/pages.asp?pageid=8

In one of the tutorials you will find similar code to what ive just shown you,

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.