How to Store Tiles

I just wanted to ask what is a better solution to store a lot of tiles(and the related information like heat or light).
Here are the two solutions i could think of:

  • Store the information of an tile in one object and then store all these objects in an 2D array
    or
  • Store every single information in a different 2D array

Object(only properties and image, pos can be calculated by mult. Tile size by x and yoposition in the array) + 2D array :slight_smile:

Thanks

If you want to have arbitrary map shapes and/or discontinuous maps that are freely expandable, consider a Map (heh) instead of an array.

E.g. [icode]Map<Point, Tile> tiles = new HashMap<>();[/icode]

There are various memory usage optimizations for it, but that should give the general idea.

Hi Islidius,

There are many options :stuck_out_tongue:

1)Two dimensional Array and Tile’ class objects
Advantage: easy to find coordinates
Disadvantage: i see many people suggesting one dimensional Array, and it has something to do with memory, but if you don’t need ten thousands of tiles, that shouldn’t be an issue right now :slight_smile:
2) One dimensional Array and Tile’ class objects
Advantage: the data structure is smaller, and the iteration is really easy and fast
Disadvantage: you have to write a little method to find coordinates, but nothing fancy.
3) BurntPizza’s idea

And probably so many different others :stuck_out_tongue: