Quick Start: Part 2

Include tags

Although at the moment you’ve only got a single resource, eventually you’re going to have lots of different resources. Keeping them within one file can be messy, so it’s often best to split them into different files. To include one resource file from another, use the ‘include’ tag:

Remember that the ‘tanks.xml’ file should also have a top-level tag.

Parent resources

Often in games we want to define a basic enemy (or item, or behaviour, etc.) and have several variants of this with minor tweeks. Parent resources mean you don’t have to duplicate the common values between these resources. For example, if we had a basic tank:

We can define a base tank and several variants on it:

Parent resources must be defined before they are referenced in a child resource. For best results they should be in the same file as all child resources (so that parent and children get reparsed at the same time).


Writing your own resource types is great, but sometimes you want to use a 3rd party type (such as java.awt.Point) which you can’t modify yourself. Instead you can write a decoder to add Point support.

Decoders are classes with a static ‘decode’ method which accepts a String (or xml Element) and returns the decoded object:

‘Type’ is not a generic parameter but the concrete type you wish to decode. A simple java.awt.Point decoder would look like this:

Once you’ve written your decoder, you need to register it in your resources xml with the ‘decoder’ tag:

Element decoders work the same way, except that they accept an ‘Element’ argument, and the syntax to use them in a resource is different:

Background Loading

So far we’ve used ResourcePool.parse() and ResourceHandle.forceCreate(), which will work just fine but are blocking calls and do all of their work in the main thread. For non-blocking behaviour (for example, to display an animation while loading) usage is slightly different.

Instead of ResourcePool.parse(), use ResourcePool.backgroundParse to parse in a background thread:

ResourceHandle.forceCreate forces a resource to be fully created straight away, however if it is not currently created this will block as any remaining creation is done. Instead you can request a resource be created in a background thread with ResourcePool.requestCreate():

One method is to requestCreate() all resources required for the next stage/map, and show a loading screen until they all report that they are fully created before continuing.