SpritePlacer a level editor

Straight off the code is at https://github.com/chriscamacho/SpritePlacer As its using libGDX its cross platform, however if you want it to work on a Mac or Android device you’ll need to add your own simple platform stub.

There is nothing special about this simple level editor but it does boast a rudimentary file selection dialog, which is separate enough that you should be able to very easily integrate it into your own projects.

I have to say that I struggle somewhat with libGDX’s GUI as do anything in the wrong order and all sorts of odd things happen! This isn’t helped by the far too sparse javadoc and a wiki that usually just shows you a small bit of code instancing some widgets but not really using them or explaining how they are intended to be used…

But still you can usually bully it (eventually) into some sort of behaviour even if you’re unsure you’re using it in the right way!

LibGDX’s Sprite class is wrapped into a pixy class to store extra properties and also utility functions and a static list of all created pixies.

I chose to save and load from XML and while its only a single layer of hierarchy I still found XML useful.

Saving was by far the easiest task after dumping a very simple header its quite straight forward to iterate in turn through each pixy. The pixy class has a simple method to dump an XML representation of itself to a string.

Loading was a little more complex but I used the built in SAX parser as it doesn’t load the whole document into memory as an object.  The SAX parser uses callbacks as its traversing the document, which once you get your head round actually makes like easier.  Still that said saving is a one paragraph method and loading is a whole multiple method class in its own right!

Although probably not an ideal example of an XML parser, its probably a fair real world example to inspire your own parser (off the top of my head I can think a few ways to improving it – oh dear there I go again wanting to fix working things!)

In the future other than on going tidying I plan to add some kind of more useful user defined data than just a string and may also consider adding scripting and even box2d support.

Development is rather sporadic, but then no one knows about it to contribute so its just me when I get chance…

 

Leave a Reply

Your email address will not be published. Required fields are marked *