Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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 1484 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:

1:

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?

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<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.

thanks!

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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (34 views)
2014-12-15 09:26:44

Mr.CodeIt (25 views)
2014-12-14 19:50:38

BurntPizza (52 views)
2014-12-09 22:41:13

BurntPizza (85 views)
2014-12-08 04:46:31

JscottyBieshaar (47 views)
2014-12-05 12:39:02

SHC (61 views)
2014-12-03 16:27:13

CopyableCougar4 (63 views)
2014-11-29 21:32:03

toopeicgaming1999 (125 views)
2014-11-26 15:22:04

toopeicgaming1999 (115 views)
2014-11-26 15:20:36

toopeicgaming1999 (33 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!