Collisions on map

How can i make collisions for each tile of my map?
I don’t want collisions all the same for each tile of the tileset

If you don’t want collisions all the same, you’ll need to draw collisions manually on each map. These are the usual options for doing so:

  • Use special tiles for collision, on their own layer. Don’t display these in your game, use them only for collision. Don’t even look at the collision of tiles on other layers. This way, the collisions would be all the same for each instance of the special tiles, but the special tiles can be independent of your visible/cosmetic tiles.
    • For the actual collision on these, you can use Tiled’s collisions, or you can manually parse collision based on custom properties on the Tiles or tile IDs.
  • Use collision Objects and draw collision using Rectangles and/or Polygons. These would let you have collision boxes that are larger than tiles, grouping several tiles in one object, which may be faster to check collisions against in some games. The downside to this approach is you’ll need to take special care to make sure your collisions align to the tile borders, but if you enable Snap to Grid in View > Snapping, this should be easy. You’ll also need to make sure you parse these Objects as collision when you load the map. Putting all of them on a “Collisions” layer should simplify that.


I’m trying to do this using monogame.

  • Can you check this example here (especially LoadContent() in Game1.cs) to see if this is what you mean? You can find the map in Content folder

Is it correct this is the first option you told me?

  • Do you have an idea how to do the 2nd option using TiledSharp or TiledCS (to read the map) in combination with monogame (to do the actual collision)?

I’m not familiar with TiledSharp or TiledCS, but it looks like the repo you linked does the 2nd option - it looks for a layer called “Collisions”, and reads in any Objects on it into collisionObjects, which is used in Update(). It reads every object as a Rectangle though and won’t work correctly for non-Rectangle Objects, so if you’re using this code, make sure you only use Rectangles for collision.

For doing the actual collision, the example you linked is something to look at. It just iterates over the list of collision rectangles and if the player’s new position would intersect any of them, it doesn’t let the player move. This is a very basic way of doing collisions, but it’s good for a starter project :]