Hello everyone! I’ve made a editor for a tile based game I’m working on, and it’s OKAY for now.
I’m not sure about premade map editors, because I might not like the format these give out. I hope there is one that can save the map as a xml file which I could use a xml transformation to change it to a format I can use.
So the big problem now is how the map is stored in memory. I was thinking of using a ArrayList that I could index into using an int[][][], or short[][][], the first index would be the layer. This seemed like a fine idea at the time, until I realized this would waste a large amount of memory for a layer that doesn’t have much on it. So I heard of a solution which is to represent a tile as a linked list, such a Tile would be linked to the the next Tile (for the next layer) and so on, they would be painted in this order. This would allow for the map to have the smallest amount of memory required. I realised there were different ways of doing this:
1:
Represent the map as a 2D array of ArrayList or LinkedList objects, each Tile would have an index into the image array and blocking information:
class Tile {
boolean blocking;
int image;
}
the ArrayList would grow as required by memory. The map would look something like this:
class Map {
ArrayList[][] background; // renders behind player
ArrayList[][] foreground; // renders over player
ArrayList[][] roof; // invisible when the player walks under it
}
I was thinking that the ArrayList is possibly too heavy weight?
2:
Make a Tile class with a link to the next one:
class Tile {
boolean blocking;
int image;
Tile next;
public Tile getTile(int index) {
Tile next = this;
for(int i = 0; i < index; i++) {
next = next.getNext();
if(next == null) {
return null; // break out of the loop early to avoid exception
}
}
}
return next;
}
public Tile getNext() {
return next;
}
}
this would probably be less heavy weight than the original but would require me to do some more research about how to make a good linked list, probably wouldn’t be too hard.
Should I store the Tiles or ArrayList (for the first method) in a one dimensional array like this:
1: ArrayList[] background = new ArrayList[mapWidth * mapHeight]
for accesses: images.get(background[tileY * width + tileX].get(1).image);
2: Tile[] background = new Tile[mapWidth*mapHeight];
for accesses:
Tile tile = background[tileY * width + tileX].get(1);
if(tile != null) {
BufferedImage bi = images.get(tile.image);
}
is it better to have the map width and height a power of two?
I know there are a lot of questions, you don’t have to answer each one. I’m grateful for any advice.
thanks!