How do you load and setup your levels/menus?

Hey,

I’ve been trying to think of a good, and simple, way to load all the information (data in text files, sprites, etc…) and setup levels/menus for my game. So-far I’ve managed to write up a few different methods for to load all of the files and then convert those files into Entities, interface pieces, etc… Although all of the ways I’ve tried do end up working to some degree, the code is an utter train-wreck compared to how nice and neat the rest of my code is. It’d probably be easier if I wanted to code more of the data and that in, but I’m trying to set it up so that you just need to have the right folder structure and files to load anything into the game.

Since it wont hurt to ask, how do you load your levels, menus, and whatever else?

well menus are hardcoded - what do you load ?

as for maps I just developed a map editor which serializes using kryo the map and can load it again.
Never that simple but yeah. short answer is write a parser or use serialization.

what exactly are you saving/loading ?

There is no simple way.

The best way to make UI I know of, is something like that:

  • Make a graphical UI system yourself for you game (Like GWT / Swing). That would need to contain things like buttons, images, labels, scroll things and anything else you need;
  • Now you need to use format like JSON or XML to load your menu data from these formats. I think JSON is much better for readability purposes. After you parse JSON file, you need to load each node into your UI system;
  • Now that your UI system contains elements which were described in JSON, you can edit those elements to your liking in code, after they are loaded;

Again, there is no simple way to make menus. It depends on the complexity of the menus you want to achieve. The more complex the menu you want, the more messy the code will be… That’s like a fact for me at least.

I wrote a simple framework for custom interface components. As a simple example… When creating a button I need to load the X/Y coordinates of the button along with three sprites for the default, clicked, and hovered states of the button. The same thing applies to all tiles, NPCs, etc… in the game. To make it really simple. Almost nothing is hard-coded with the way I have it set up. A few things will probably have to be hard-coded eventually, but everything is just “load-n-go” atm.

Your serialization idea sounds like a simple solution even though it would require a fair bit of extra work to setup at first. Thanks, I’ll look into it.