I'm trying to find a way, or should i say i have been trying to find a way to load the tiles for my game into and array of some sorts but im struggling to find the best way to go about it. I have a folder design - images/tiles/*tileset*/example.png - I can get all of the files listed from that directory i just cant load them all into some form of referenced array.
What I do is make a 'tile' object that contains the x and y location of the tile, and anything else you need it to have (is it solid, dangerous etc) as a well as a draw function. Then, I make a 2d array of these tile objects in a 'map' object that handles drawing and initializing the tiles etc. That's just me though, I'm sure there are other ways.
As for loading them, you can use several methods. my personal favorite is to pixels from a image file (lets say red is ground and blue is air, that kind of thing) but I've only ever done that in C++. for Java I've used text files. I think you can also use objectoutputstream stuff which I'm sure is more professional. I'm a bit shaky on the whole loading/saving tiles bit, so you may want to do some other research.
Joined: Jun 06, 2012
Ahh thank you i wasn't sure whether too create a class array to store my tile but i think now that may be the best option thanks.