I’m working on a game that utilizes tiles in a weird way. It’s not your average kind of game where I could just make a nice default texture and focus ‘the camera’ on a certain section.
Think of the game sort of like minecraft-- the terrain at the start is randomly generated and it’s absolutely massive in terms of size. For example, I started getting “out of memory” errors when I wanted to make a 2D int array that had 10000 x 10000 indexes [is that the proper plural?]… I tried storing the tile number in an int[][] where the arrays were an int(x)(y) :(. Thus, I can’t store all the tiles I want in a memory array. How would I go about storing the tiles in a file?
Thus far they only have to be numbers, very basic. I could even write them as bytes at this point, but I wanted to keep integers to allow for more stuff later on.
Basically my game works like this-- or rather this is how I want it to work (if you know a better way I’ll change it guaranteed, remember I am a noob :)):
- Interface draws tiles from top left to bottom right (2D flat game, no isometrics or anything). It draws 16 x 16 tiles on the screen.
- Lets say it wants to draw from (x, y) down to (x + 16, y + 16), the code would go like:
for (int a = x; a < x + 16; x++)
for (int b = y; b < y + 16; b++)
// draw code here
Actually I probably did the height last and the width first, but either way: that the only way I can think of rendering a dynamic world.
- NPCs and stuff would be in a different file or loaded into the game as an object directly instead and are drawn on the tiles (should I also store these in a file somewhere?)
I don’t know how to go about properly formatting the tiles for storage. I heard XML files are great, but I don’t know how feasible it is for it to read 16x16 tiles every 20ish milliseconds.
Are there any better ways to go about reading/writing/printing 2D tiles on an interface than how I’ve proposed? Please note that I’m still learning java, though I’ve done 2-3 other languages so I understand how syntax works… hope that helps!