1
\$\begingroup\$

I'm not sure this kind of question has been answered yet, if so i'm sorry to duplicate it.

My question is rather simple :

I'm creating a simple Isometric game with libgdx, i'm using Tiled but only to design the map and render it with OrthographicMapRenderer.

The map is a static map of 6864 * 6880 pixels, one tile is 59*43 pixels

I wanted to do some pathfinding to my game, so I decided to store my map data into a simple 2D array like this : int cells[i][j] which would contains 0 if the tile is walkable or 1 if it's not, it is as simple as that !

Currently I've simply using basic formula to convert world cartesian coordinate to Isometric coord, and formula to get tile pos based on iso pos, (eg : you input a iso coord, the function return a vector like <2,5> which is the 2nd x tile and 5th y tile.

It perfecttly work as execepted, I also make it that iso tile coord is always positive ( <0,0> is at the top left corner of my world )

But here is my Question or doubt : How to handle correctly the game data tile ? Does a 2D array is sufficient, if yes, how to, for exemple write a function that get if a tile is walkable or no based on tile coord ? ( example : I click on my map, the coordinate is translated to tile coord ( < 4,5> for example,) how to check if this tile is walkable ?, i dont get on how to do it i'm really lost.

EDIT : Ive successfully implemented the isometric logic : I can convert world coordinate to tile coorinate ( eg : (5075;4851) -> (203;28)) and the reverse but i'm confused on how to fill the 2d Array, use it for A* algorithm and make the bridge between these coordinate and the 2D array

Thank you for you help, Regard

\$\endgroup\$
2
  • \$\begingroup\$ libGDX AI comes with a great pathfinding utility libgdx.badlogicgames.com/ci/gdx-ai/docs/com/badlogic/gdx/ai/pfa/… \$\endgroup\$
    – BenR
    Commented Nov 8, 2018 at 20:20
  • \$\begingroup\$ better late than never like we said haha, By the way i've already solved my problem, and in fact with a Indexed A* pathfinding implementation of the one in LibGdx ! Thank anyway ! \$\endgroup\$
    – War-sloop
    Commented Nov 9, 2018 at 15:59

1 Answer 1

1
\$\begingroup\$

This answers is valid for any language or framework.

I would wrap the tile info on a class, called for example "MapTile" class. This MapTile will have all the data you need, like if it's walkable the type, the name, an unique Id..

then on the array you will put this MapTile class, and you can access from there to the Tiled info an other any info you want to have there using getters, and change it if you want using setters

To make it easier to manage, I recommend you to create a "TerrainType" class that will have the different terrains that your game will have, so you don't need to repeat that data every time you initialize a tile. Initialize them at the start and save them to an Array so you can reuse this read only data to any tile you add to your main array.


TL;DR;

  • Create a TerrainType class (or use an enum, whatever you feel like).
  • Create a class MapTile that is initialized with the information of this TerrainType and extra info you might add like ids, names, if there is something over the tile (use setters to change this at any time)..
  • Add to your Array the MapTile class. Now you can access to all the data in this MapTile, including the TerrainType with all the info you may need.
\$\endgroup\$
6
  • \$\begingroup\$ thank for your answer, but that is not really what I needed... Let me explain a bit further : Ive only one type of terrain, there is 20 differents maps but with the same size, the only thinks which change is the map tiles, aka some props on the maps, but thats all, I just want to know how to handle the map data. there is only 2 type of tiles : walkable or not. do I need to deal with iso coordinate and not tile one ? \$\endgroup\$
    – War-sloop
    Commented Aug 25, 2018 at 16:34
  • \$\begingroup\$ It's the same, if i'm understanding correctly. Just save on the array a wrapper class with the minimum data you need to draw, update and handle cases. Sorry if I can't get through. \$\endgroup\$
    – Oscar O.
    Commented Aug 25, 2018 at 22:02
  • \$\begingroup\$ if not, you can have another array with the same positions filled with true or false and check both of them to know if you can pass or not \$\endgroup\$
    – Oscar O.
    Commented Aug 26, 2018 at 9:15
  • \$\begingroup\$ Thank you, yes I understand what you explain, but my main problem is how to store my map data, and make the bridge between where I click on my world and the tile selected on the array, do I need to store my map tile data as cartesian coordinate and then when I click I convert my tile coord to map coord ? you know what I mean ? \$\endgroup\$
    – War-sloop
    Commented Aug 26, 2018 at 9:32
  • \$\begingroup\$ Now I get it, it wasn't clear. Well, I don't have any example now, but an Array[][] should be a valid option for any 2d tile map (including isometric). In this case, you would need to unproject the click of the mouse to your camera and then calculate what position are you clicking. This depends more on your implementation of the world. @War-sloop , you can see how others done it here: gamedev.stackexchange.com/questions/29396/… \$\endgroup\$
    – Oscar O.
    Commented Aug 26, 2018 at 9:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .