简体   繁体   中英

What is the best way of saving a tile grid to text file for a java game?

I've been working on making a level editor for a game i'm creating. I want my levels to be saved as text files with individual characters representing different objects in the game. So far in my level editor, you can only place one kind of object in different tiles of the grid but, there's no way to save the level. What is the best way of getting the x and y coordinates of the objects and placing them in a text matrix accordingly?

You could use XML like so:

<map>
<row><tile>LAVA</tile><tile>LAVA</tile></row>
<row><tile>WATER</tile><tile>STONE</tile></row>
</map>

I want my levels to be saved as text files with individual characters representing different objects in the game

you could just map characters to tiles and either be consistent with what they map to or store a key with the table.

Your text file could look like this:

LLLWW
LLWWS
LLWSS

optionally with a key at top, something like

W=Water,L=Lava,S=Stone

etc.

It would be preferable to use XML or JSON though, as this will allow you to more easily expand in future and there are tons of libraries out there for parsing json and xml. Using a character to object representation limits the amount of data you can store in the map file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM