GLEED2D level loading system for libgdx

Update: the system had been moved into the official libgdx repository as an extension but then it was removed. Gleed doesn’t support basic features such as relative paths for textures.

I’m happy to announce that I’ve made my first contribution to a relatively big open source project. I feel honoured to contribute to the brilliant libgdx framework with these humble loader and renderer for GLEED2D levels. Hold on, what the hell is that? Please, read on.

About GLEED

GLEED2D is a non tiled based open source general purpose level editor. You can place textures and shapes, rotate and scale them. As usual, elements are laid in layers and it is also possible to add custom properties which makes it adequate for all kinds of purposes. Level are saved in an easy to parse XML format. It’s based on XNA 3 but XNA 4 and Mono versions are on the works. What’s good aboutGLEED2D is that it allows you to create smooth levels in a very nice way. Shapes can be used to define collision areas, triggers and so on.

This means you can set a few rules and conventions of your own and be able to fire up scripts, set the player spawn point and all sorts of level design sweetness.

GLEED2D editor in action with some shamelessly borrowed Braid’s assets

Features

  • Full XML GLEED2D spec: layers, custom properties, textures, shapes (circle, rectangle, polygon), visibility, color tints…
  • Transforms: object positioning, rotation and scaling.
  • LevelRenderer class with frustum culling
  • AssetManager integration through the LevelLoader class
  • Use multiple Texture files or a single TextureAtlas for performance gain.

Possible improvements

  • Make the renderer use a SpriteCache (tricky due to texture rotation)
  • Create a JSON exporter and loader for performance gain
  • Load levels without using the AssetManager? Some people don’t use it but they really should since levels tend to be heavy to load
  • Suggest more!
GLEED2D system running ingame

Usage

When creating the level you need to specify the textures root folder or atlas file as a top level custom property:

  • If using individual textures create the “assetRoot” property
  • If using an atlas create the “atlas” property
// Set loader in the Asset manager
m_assetManager.setLoader(Level.class, new LevelLoader(new InternalFileHandleResolver()));

...

// Tell the manager to load the level
m_assetManager.load("data/braidtest.xml", Level.class);

...

// When it's ready, fetch the level and create renderer
m_level = m_assetManager.get("data/braidtest.xml", Level.class);
m_levelRenderer = new LevelRenderer(m_level, null, Game.mpp);

...

// Render all layers
m_levelRenderer.render(m_camera);

However, if you get lost, there are Javadoc comments everywhere in the code.

Where do I get it?

It should be soon in the libgdx nightly builds but if you’re really eager to use it and can’t wait any longer (seriously?) you can go to the libgdx repository and find it in the extensions section. Remember to leave some feedback of any flavour: rotten tomatoes, rocks and so on and so forth.

  • http://none Mikle

    Hi. When are you going to create a JSON exporter and loader?
    Thx.

  • http://siondream.com David Saltares

    I honestly don’t know cause this is a side project apart from work so my time investment capabilities are quite limited. I also want to push the project forward so I end up having a game and not a nice set of tools. You can always check the code out and try to implement it yourself. That’s the beauty of open source ;-).

  • Javier

    Muchisimas gracias David. Voy a probarlo hoy. Un abrazo!

  • http://gravatar.com/idontwantyourspamthanks idontwantyourspamthanks

    LevelLoader doesn’t exist, import aint happening, any ideas? Surely can’t be buggered after 2 months?

  • http://siondream.com David Saltares

    It has been merged into the libgdx project as an extension https://github.com/libgdx/libgdx/tree/master/extensions/gdx-gleed

  • http://gravatar.com/idontwantyourspamthanks idontwantyourspamthanks

    Gracias, you might want to update the main article accordingly as all the links are 404sid

  • http://siondream.com David Saltares

    I know, sorry about that, will do.

  • http://siondream.com David Saltares

    Updated!

  • KLIS

    I was just starting a project on libGDX and found your extension! A little doubt, can I use the extension with projects written on LibGdx nightly build!

  • http://siondream.com David Saltares

    Not for now because it’s on a different branch on the GitHub repo. It will be merged into master soon and, hence available in the nightlies. Check this for more info [1].

    [1] http://www.badlogicgames.com/wordpress/?p=2829

  • KLIS

    Ah nice! I will wait for it and also great work David! :)

  • http://gravatar.com/idontwantyourspamthanks idontwantyourspamthanks

    That’s pretty cool :) Gonna keep going with Flock Off using this version for now, but will retool to the libgdx-master variant for the next project. Display is looking very tasty, just about to dive into the art of collision detection (ie collisions between my sprites and items on the gleed2d background) which should be fun!

  • http://gravatar.com/insane333 Anik Hasan

    What is InternalFileHandleResolver ? Where do I get this class?

  • http://siondream.com David Saltares
  • MJ

    Hi guys!
    Am I ok or I think that LevelLoader is not available anymore in the libgdx framework? I was trying to use the LevelLoader object but my libgdx version (the latest nightly build) does not recognize it…
    Please if you know where to find this, let me know.

    I appreciate so much your answers.

    Regards,
    MJ

  • http://siondream.com David Saltares

    After the new maps API came in, the loader changed and went into the core but it has now been deprecated. The reason behind this is that Gleed doesn’t support relative paths so it was a bad candidate to use as an editor.

    • wangzw

      What a bad news…. Could you recommend any other candidates can create UI like Gleed2D?

  • MJ

    Oh, it’s a shame :( – So, that means that the loader is not available anymore? Or there is a way to use it? I was excited when i read that integration with gleed, since it allows you to create 2D maps freely without the need of tiles.

  • http://siondream.com David Saltares

    You can always dig through the history of the repository and back integrate it yourself with a current build. You’d need to work from the sources though.