2
\$\begingroup\$

I'm developing a J2ME game which uses tiled backgrounds for the levels. My question is how do I store this tile information in my game. At the moment it is stored as an array; with each number representing a different tile from the tile-sheet. This works well enough, however I don't like the fact that it is 'hard-coded' into the game because (at least in my opinion) it is harder to edit the levels, or design new ones. I was also thinking that it would be difficult if you wanted to add a 'level pack', I'm not sure on how this would be achieved though; it's not something I was planning on doing, I'm just curious.

I was wondering if there was a way I could store level data in some external file and then load this in to the game. The problem is I don't know what the limitations are for J2ME regarding file I/O, can it read in any file like Java? I am aware of the RMS, but from my experience I don't think this would work (unless I am mistaken).

Also, would loading the data in this way be too big a performance hit? Or is there another way I can achieve what I am trying to do. As I said, the way I have it at the moment works fine, and if this is the only viable option then it will suffice.

\$\endgroup\$

1 Answer 1

3
\$\begingroup\$

Loading the tile information from file would work just fine. A very basic format would be a matrix with IDs like this:

0 1 1 1 0 2 0
0 1 1 1 0 2 0
0 0 0 0 0 2 0
0 3 3 3 3 3 3
... etc.

You can then read this in and split by space/newline to get an array.

Another option is using an editor like Tiled or OgmoEditor which can both save to an XML format you can read and parse within Java. You should be able to read files using J2ME too.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .