Table based map

Updated on February 22, 2018 in [A] 2D
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
4 on August 15, 2014

I would like to create a map from tiles. I guess this is how pokemon map was done. What I mean is let say an int table[20][20] and each field has its own “number” which determines the tile used. Lets assume every tile has a size of 50x50px and has its anchor point in top left corner. If the cell is [0][0] and its value is 2 I would like the tile named for example 2.jpg be put on the map with coordinates [0][0] then if cell [0][1] has a value of 5 I would like the tile named 5.jpg to have coordinates [0][50] and so on and so on.

Is it reasonable way to do this? If yes how actually I should do this in unity?


EDIT: I found something like that:
What do you think about it?

  • Liked by
2 on August 15, 2014

if your tiles are 50x50px, in the inspector set pixels to units as 50. This makes so each tile is one unit exactly.
Now just set each tile to a position that’s an integer. e.g. one tile at (0,0) one at (0,1).

If you want them to keep track of their position via a script, use a Vector2:
public Vector2 pos;
void Update ()
pos = (transform.position.x, transform.position.y);
is that what you’re looking for?

on August 16, 2014

Kinda, but is it good way to do this or there are more efficient?

on August 16, 2014

well, the alternative is to put the tiles together in a program like photoshop and then just add colliders in unity.

This way is much easier. Just make sure you have each tile type as a prefab.

Show more replies
  • Liked by