Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (687)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Tile based map formats for fast display --  (Read 1653 times)
0 Members and 1 Guest are viewing this topic.
Offline Thinking

Senior Newbie

Java games rock!

« Posted 2005-04-20 21:58:08 »

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<Image> 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:


Represent the map as a 2D array of ArrayList<Tile> or LinkedList<Tile> objects, each Tile would have an index into the image array and blocking information:

class Tile {
 boolean blocking;
 int image;

the ArrayList<Tile> would grow as required by memory. The map would look something like this:

class Map {
  ArrayList<Tile>[][] background; // renders behind player
  ArrayList<Tile>[][] foreground; // renders over player
  ArrayList<Tile>[][] roof; // invisible when the player walks under it

I was thinking that the ArrayList<Tile> is possibly too heavy weight?


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<Tile> (for the first method) in a one dimensional array like this:

1:  ArrayList<Tile>[] background = new ArrayList<Tile>[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.


Offline Deadcow

Senior Newbie

Back from beyond ... Moo!

« Reply #1 - Posted 2005-04-21 06:41:55 »

Once again, quadtree comes to mind. Some other people have explained it better than I can, so feel free to ask google for it =). Quadtree is a space partitionning tree for 2d space ( Octrees are for 3d space ). Basicaly, you got a root node covering the entire area of your map. The root contains four sub-nodes dividing the root area in four parts, and so on recursively to a given depth. So, looking for the tiles in a given area is done by traversing the tree, branching to the appropriate sub-nodes until you reach the area you'r interested in.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Dwinin (70 views)
2015-11-07 13:29:08

Rems19 (80 views)
2015-10-31 01:36:56

Rems19 (72 views)
2015-10-31 01:32:37

williamwoles (106 views)
2015-10-23 10:42:59

williamwoles (92 views)
2015-10-23 10:42:45

Jervac_ (106 views)
2015-10-18 23:29:12

DarkCart (134 views)
2015-10-16 00:58:11

KaiHH (116 views)
2015-10-11 14:10:14

KaiHH (155 views)
2015-10-11 13:26:18

BurntPizza (171 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!