Level creator

I’ve recently begun on a new game called “Waffleocolypse”. I have the character, platforms, coins to collect, and one enemy. I would like to make a level creator, but I don’t know where to start. I also need a method of saving that world to some sort of format that can be read by the game in order to play it. Does anyone have any experience in this that can help?

I suppose that you are talking about a 2D game. You could either use Tiled, a tile based 2D editor, or just save and load the levels from plain text files. I have never used Tiled so I can’t tell you how it works. However, for the text files you might represent every entity of your game with a number, e.g.: 0 = character, 1 = coin etc.

You should google a little bit for parsing text files in Java.

I have used Tiled and I strongly recommend it for tile-based games. It also supports polygons, but it is not as well developed in that area (yet?).

Tiled can save levels in both XML and JSON.

Good luck!

Also, if you use the Slick2D library (as I do) then there’s a class that automatically loads a tiled map from the Tiled program. There’s a very useful Camera class that’s on the Slick2D forum which really needs to be in the core Slick2D code. That camera class scrolls around the Tiled map object.

As far as saving data here’s one way:
Create a level configuration class which holds all the level data. It has nothing to do with how the level works, it’s only a list of objects on the level and the tiled background which the level should use. Create and fill that class and then marshal it to XML using Jaxb. Inside your game just get the XML filename and marshal it back form XML to Java and it will automatically create and fill your level configuration class.

There are many ways to do this. You could also use Java Serialization. With Serialization every time you change the format of the class you’re saving the old serialized file will no longer work. So be aware of that. It’s easier than Jaxb, but as things change serialization can be frustrating because you have to re-save your level to get the new serialization file.

The problem is that I’m not using tile based… It’s side scroller…

So you can not represent the level with tiles or is the problem something else?

What are you planning to use for representation? Polygons? Pixels?

I can not really recommend Tiled for polygons. I tried to use it for this game but it is lacking a lot of useful features for polygon manipulation.

I was planning on using sprites to represent it. The problem would be creating a system that stores ArrayLists to a sort of file that I can reopen with the game and parse out the List.

I’m making a sidescrolling platformer, which is what I gather you’re making, a tile map, should be fine for doing a sidescroller, it’s what Im using, plus its easy to do everything can be stored in a 2 dimensional array.

So by “sprites” you maybe mean positioned rectangles, maybe rotated/scaled etc.?

Tiled is pretty good for custom rectangles, but if you want them scaled or rotated with a custom pivot point, I would use something else :). Its probably OK if you just have an angle property and that the pivot point is always in the center.

Here is an example of a (JSON) Tiled level that uses positioned rects and polygons
It represents the first level in that game I referred to earlier.

Here are some more examples: Gui components, Icons, A ship, Font!

I’m just intrested… How do you acctually use JSON files?

They are simple… Do you need to write a parser yourself, or are there libs in the Java SE? I really like them…

You use a third party JSON parser, and there’s more of those than you can shake a stick at. Two really good ones to get you started:

http://jackson.codehaus.org/

That README from the first one looked really impressive…
totally offtopic: Why the heck use XML? Parsing XML is much slower, than parsing JSON, I’m sure!

There are a few reasons some data formats choose XML:

[] It can have comments
[
] Deep nesting has more visual cues (no counting curly braces)
[] It’s easier to put nearly arbitrary text in CDATA sections
[
] Entities give you a sort of primitive #define-ish macro system built in
[*] There’s a lot of tools for querying (DOM, xpath, xquery), validating (xsd, rng), and transforming (xinclude, xslt)

What’s nice about Jackson and XStream is that you can use the same API for both XML and JSON.

I would have used XML if I didn’t create the game in Javascript. I use XML for everything else if I get the chance.