Data structures for a 3D array
- by Smallbro
Currently I've been using a 3D array for my tiles in a 2D world but the 3D side comes in when moving down into caves and whatnot. Now this is not memory efficient and I switched over to a 2D array and can now have much larger maps. The only issue I'm having now is that it seems that my tiles cannot occupy the same space as a tile on the same z level. My current structure means that each block has its own z variable. This is what it used to look like:
map.blockData[x][y][z] = new Block();
however now it works like this
map.blockData[x][y] = new Block(z);
I'm not sure why but if I decide to use the same space on say the floor below it wont allow me to.
Does anyone have any ideas on how I can add a z-axis to my 2D array?
I'm using java but I reckon the concept carries across different languages.