Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading and storing tiles?

 
Marcus Setchell
Greenhorn
Posts: 10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic