*
The moose likes Game Development and the fly likes Loading and storing tiles? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Loading and storing tiles?" Watch "Loading and storing tiles?" New topic
Author

Loading and storing tiles?

Marcus Setchell
Greenhorn

Joined: Jun 06, 2012
Posts: 10
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.

Thanks in advance

Marcus.
Wes McClintock
Greenhorn

Joined: Jul 19, 2011
Posts: 25
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.
Marcus Setchell
Greenhorn

Joined: Jun 06, 2012
Posts: 10
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.

Marcus.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading and storing tiles?