Jump to content

Tile maps json - collision approach


przemoo83
 Share

Recommended Posts

Hi
I'm creating some simple json tilemaps in Tiled and in order to decide which tiles player should collide with I just open a json file and look at the matrix to identify proper numbers. I'm sure there's a better approach because if my map was really huge it would be impossible to identify  tiles in this way. How should I do it properly ?

Link to comment
Share on other sites

What shakeshake said... I would add that doing it this way gives you much greater freedom than using the tile values in the display map.  For instance if you want to make a hidden door in a wall, instead of making an exact copy of the wall tiles and tagging them so they don't collide, you can use the same tiles in the display map and just tag that part of the collision map as no collide.

If you do anything with a forced perspective angle, having a separate collision map is nearly essential to get good collisions against the multiple layers of the display map.

 

However, if you really really don't want a separate collision layer, the easiest way to do this is to group your tiles so that all the ones that collide are at the end of the tile list, and all the ones which don't collide (including the empty tile) are at the beginning.  Then you only need one number - the point where it switches... and you can pad the no-collided tiles so that number is always 128 or something easy to remember like that.  For collisions you just say:

if (collidedTileNumber >= firstCollisionTileNumber)

// we collided

else

// we didn't collide

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...