Screen Manager and Level Editor

Happy Tuesday!

The last couple weeks I have completed a lot of the initial footwork to get the game up and running. In the end I was able to complete three major game components: the Screen Manager, Level Editor, and XML serialization/deserialization.

Before we get into those, it’s worth discussing my game organization. The game is split into three projects: Game, Content, and DataTypes. The Game project contains the main code to be executed during run time, including the main game and level editor. The Content project contains all of my textures, tilemaps, audio, and fonts that will be loaded from my Game project during run time. The DataTypes project is used to define any types used during the XML serialization process (The reason this is separated is due to cyclic referencing when the XML tries to build using a type that is defined within the same project, see build time vs run time).

The first component that I was able to complete was the Screen Manager. This component controls was modeled after the Game State Manager tutorial and these Screen Manager posts. The Screen Manager component keeps a list of all of the game’s possible screens, currently containing the StartScreen, ActionScreen, EditScreen, and LoadingScreen. The StartScreen contains the main menu with entry points to the ActionScreen and EditScreen, which contain the active gameplay and the level editor respectively. The Screen Manager is responsible for keeping track of which screen is the active screen and invokes its update and draw methods.

Simple StartScreen with menu options

I decided to create a simple level editor because creating ASCII level files or manually editing XML was quickly becoming unmaintainable. So I created a simple level editor in which I could interactively add and delete tiles from the screen. In addition, I could select different color tiles to draw onto the screen. This quick implementation is nothing fancy, but it allows me to quickly develop levels to load into the main game.

A simple level editor creation

Simple level editor creation

Once I draw a level onto the screen, I needed a way to save that and load it into my main game. I did some research and discovered an interesting solution: XNB Serialization. By creating a TileData class in my DataTypes project, I was able to fill an array of TileData objects and serialize that into an XML file containing my TileData definitions. Then referencing some XNA Storage tutorials, I was able to save that XML file to disk. Finally, once the XML is added to my Content project and recompiled, the XML files compile into XNB files which can be deserialized back into the TileData array on the main game side at runtime. Because this deserialization plus loading all of the textures takes some time, I added a LoadingScreen to disable to active screen until the loading process is complete. This process is requested by the active screen and managed by the Screen Manager, who hides/shows the LoadingScreen upon request/completion.


ActionScreen loading level form level editor

Now with all of that out of the way, I will start working on some simple 2D physics as well as collisions. Look for updated relating to that next week!

Leave a Reply

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


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>