Skip to main content
gamedev.net
🔒 Locked

[java] Multiple Layers

Started by whiten Feb 13, 2003 at 9:25 PM 2 replies 300+ views
Original Post
whiten
whiten
I am in the process of creating a small game (tile based), but at the moment I am only using a single layer, which is for the tile map. The tile map is simply a 2d array that holds information about each tile, i.e walkable / non - walkable etc. All other sprites are simply draw on top of the map Anyway, how do a code for multiple layers in a game so that I can have a background and foreground. If possible could someone point me in the direction of tutorial or a basic code snippet to get me started. Cheers in advance
Ditto Brother Rat
Ditto Brother Rat
Just add a third dimension to your grid:

Tile[][][] tiles = new Tile[NUM_LAYERS][][]

The Isometric Land forum here should have a more comprehensive answer somewhere in it.
levendis
levendis
I strongly recommend using a double array of java.util.LinkedList instead of a trip array. You would have a lot of bookkeeping to do by moving things out from underneath others and shifting things around. It just gives more extensibility. Java1.5 is adding generics so it should be cleaner by then, but you can write to the future specs by finding the gj compiler if the casting involved with the Lists bothers you.
------http://www.livejournal.com/users/rain_is_wet/
Ditto Brother Rat
Ditto Brother Rat
OK, maybe I did steer him a bit wrong. Always start off with the interface first and then figure out the implementation later. I''d do something like:

public interface LayeredMap {
void paint(Rectangle view, Graphics g);
void addLayer(TileLayer layer, int depth);
void removeLayer(int layer);
}

Then again, I haven''t ever really gotten past the high level design stage in any of my attempts at games, so it might not be wise to listen to me...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.