Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  (question) Tile mapping: 1d, 2d, or 3d Array?  (Read 960 times)
0 Members and 1 Guest are viewing this topic.
Offline TrinityGamer

Senior Newbie


Medals: 2



« Posted 2013-05-20 19:43:00 »

Hello, I've recently started programming a game, (I mean, VERY recently). I have just gotten to the 'tile map creation' phase, and realized that there are many different methods to choose between.

The way i originally planed to do it, and the way I learned how to do it, was to just have all the tiles in 1 Array, and just augment their position once the array reaches a certain point (say, tile 7 or 8") by shifting the x and y coordinates.

However, i realized that method might not be the best suited for what i am planning to do.

The game i am starting to program is going to have multiple layers, having 2 layers for each type of 'tiles' or image needed:
1 & 2 background/panorama
3 & 4) base tiles (the ground/water)
5 & 6) item tiles/walls/ things that need a see through background

events/mobs just have their on x&y as they are thier own arrays

I need this because i am essentially making a 2d world sim game. you can build, you can farm, you can change the landscape to fit whatever you want, blah. (no, not like terreria/starbound. I'm not making a clone of them. This is styled like an old fashioned rpgs. Like a sandbox version of the old 2d harvest moon games)

However, the way i was taught how to do this, was to just do a completely different Array for each layer, but i was thinking, what about 2d arrays and 3d arrays? would one of them be easier to keep track of/program, and would one be faster for a pc to read?

So, my question(s) are:

Should i do multiple 1d arrays, multiple 3d arrays, or 1 big 3d array?
Which is easier to keep track of?
Which is faster for PCs/Macs?
Online Cero
« Reply #1 - Posted 2013-05-20 21:49:40 »

Should i do multiple 1d arrays, multiple 3d arrays, or 1 big 3d array?
Which is easier to keep track of?
Which is faster for PCs/Macs?

I would think: 2D game -> 2D arrays. More layers ? ok then a list of 2D Arrays
I think its more intutive that way

faster? well that entirely depends on how you do it / implementation / if that created overhead / more elements you have to iterate over

Offline BurntPizza
« Reply #2 - Posted 2013-05-20 22:31:25 »

Which is faster for PCs/Macs?

One thing I have learned is not to worry too much about performance unless you know it's going to be an issue (e.g. bad algorithm scaling). Instead, when you start off, do what reduces the conceptual weight of the project, what makes it easier to wrap your head around, as that is more important. If you can't figure out how to do something at all, then what is the point of making it fast?

From what I got from this, I think the 3D arrays are the way to go, either one big one, or 3 separate ones.

example:
1  
tiles[x][y][z]
where (x, y) is the world coordinate, and z is the layer you want to reference (0-5).

or you could have it [Z][X][Y], or any other order for that matter, just be consistent in the code haha!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline TrinityGamer

Senior Newbie


Medals: 2



« Reply #3 - Posted 2013-05-22 16:42:01 »

Which is faster for PCs/Macs?

One thing I have learned is not to worry too much about performance unless you know it's going to be an issue (e.g. bad algorithm scaling). Instead, when you start off, do what reduces the conceptual weight of the project, what makes it easier to wrap your head around, as that is more important. If you can't figure out how to do something at all, then what is the point of making it fast?

From what I got from this, I think the 3D arrays are the way to go, either one big one, or 3 separate ones.

example:
1  
tiles[x][y][z]
where (x, y) is the world coordinate, and z is the layer you want to reference (0-5).

or you could have it [Z][X][Y], or any other order for that matter, just be consistent in the code haha!

Yeah, after giving it some thought, I've decided to go with this. I realized, after a bit, that doing a 1d array would make trying to program the chunk loading a pain,  and having multiple 2d arrays would probably just waist time, as a 3d array does the same thing, and takes less coding.

Anyway, thanks everyone for your impute. Cheesy
Offline sproingie

JGO Kernel


Medals: 201



« Reply #4 - Posted 2013-05-24 18:01:59 »

If you have a layered map, you'll probably want something like this:

for (Layer layer: Layers) { layer.draw() }


Then your Layer class could contain an array of tiles, or for sparse layers that only have a few objects, you could always use a list or map.  So this kind of implies "list of 2d arrays".

Offline Phibedy

Senior Member


Medals: 8



« Reply #5 - Posted 2013-05-24 18:11:27 »

if you create huge tile-maps think if chunks:
1  
2  
3  
4  
5  
6  
7  
8  
class Level{
Chunk[][] chunks;
}

class Chunk{
int[][] tiles; //you could also use short for saving some ram
LinkedList<Entity> entities;
}

So you are able to check what chunks are "active" has to be drawn -> draw tiles/entities.
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.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!