I’m working on a level editor for creating XNA games.

At the moment, it only supports the 2D game engine I’m working on, but I’m planning to extend both the engine and editor to support 3D graphics (but keeping it to 2D logic for the time-being).

This is what the editor looks like when it loads:
Level Editor
The grid can be turned on or off, and the grid size will be editable in the application settings.

From here, you can load your images, and place them in the level: Level Editor Images Note: game sprites are from Lost Garden.

The engine supports the Farseer Physics engine for XNA, and the editor supports drawing polygon and rectangle collision objects (visible as magenta lines):
Level Editor Collisions

I wrote a custom processor to get the level into the game engine, so I only have to save the level in the editor and add it to the Content project in XNA Game Studio, along with the images that I’ve used:
Level Content Processor

Then I just need to add some code to the LoadContent method to load the images and create the collision objects in Farseer:

foreach (PolygonCollisionEntity poly in level.PolygonCollisionEntities)
    Body polyBody = BodyFactory.Instance.CreatePolygonBody(new Vertices(poly.Vertices), poly.Mass);
    polyBody.IsStatic = true;
    Geom polyGeom = GeomFactory.Instance.CreatePolygonGeom(physicsSimulator, polyBody, new Vertices(poly.Vertices), 1.0f);

foreach (RectangleCollisionEntity rect in level.RectangleCollisionEntities)
    Body rectBody = BodyFactory.Instance.CreateRectangleBody(rect.Width, rect.Height, rect.Mass);
    rectBody.IsStatic = true;
    rectBody.Position = rect.Position;
    Geom polyGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, rectBody, rect.Width, rect.Height);

foreach (string textureName in level.TextureResources)
    Texture2D texture = Content.Load<Texture2D>(textureName);
    level.Textures.Add(textureName, texture);

Then I can run the level:

Level In Game

The collision objects are visible as dark green lines, and the green and white boxes form a chain, implemented in Farseer, interacting with the level.

Next up I plan on implementing the following features:

  • Modify level content processor to load textures automatically, so that they don’t need to be added manually
  • Implement a camera system to be able to create larger levels and move around them
  • Add functionality to the level editor to be able to edit objects once they have been placed
  • Implement the Properties tab using the .NET Property Grid control to be able to edit the properties of selected objects

Once that’s done, it’s on to the game itself!


Published on

Dylan Black

Back to Home