简体   繁体   中英

LibGDX bytecode reader/writer

I am working on a mapeditor for my game. And I need a way to save the map. I'm working with libGDX. And use the Android and Desktop Backends.

The maps are 2d and should contain:

  • Shape / Body data (vertices/radius/type...) for Box2D.

  • Texture/Particle pos/filepath.

Questions:

  1. How to read/write bytecode in libGDX.

  2. How to make it be for example be the format .map? ( Hills.map )

all you want to do with files in Libgdx you can achieve using FileHandle Libgdx mechanism. It's very simple:

    FileHandle file = Gdx.files.local("file.txt");

This code creates the handle for your file (whatever it existed or not - then it will be created as new) you can use to make operations on the file. Writing and reading bytes can be achieved by using:

void writeBytes(byte[] bytes, boolean append)
byte[] readBytes()

Then in your situation it should be something like

    FileHandle fileHandle = Gdx.files.local("myMap.map");
    fileHandle.writeBytes(yummyBites, false);

You can read about file handling (and also what ...local() means) here:

https://github.com/libgdx/libgdx/wiki/File-handling

I'm not sure what you mean saying 'format' .map. If you mean 'file with extension .map' it's simple as that - just create and read the file with .map extension. Remember that extensions are nothin till you define how to deal with them so you can 'create' any extensions you want.

Although if you are asking how to format all these shapes, filepaths etc you should read something about XML or JSON parsing or something like this.

On the top of all - I'm not sure what you try to achieve building your own map editor - I don't know what project like it is - but maybe you will be interested in some existing map editors? The best one in my opinion is Tiled which is actually supported by LibGDX .

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