So, I promised a blog post on GLEED2D , and here it comes, I’m still not a professional in using it, but at least this post will get you up and running, and would save you couple of expensive hours setting it up like I did due to the lack of proper documentation and tutorials , specially on WP7.
Soooo, GLEED2D , what is that ? According to the author zissakos, and I quote:
GLEED2D (Generic LEvel EDitor 2D) is a general purpose, non tile-based Level Editor for 2D games of any genre that allows arbitrary placement of textures and other items in 2D space. Levels are saved in XML format. Custom Properties can be added to the items in order to represent game-specific data/events/associations between items etc.
so, in plain English, GLEED2D is a level Editor, what that means is, if you’re designing a game which has many levels and each level has it’s own map/layout. usually (before the time of level editors) you would have to hardcode every texture/position/property/animation yourself on the screen, and then load the level whenever the player access that level.
As you can imagine, this was a pain to do, so programmers evolved and created an automated way to load level, you can just write the texture name and position and other properties for each texture in each level and save it in a .txt file or something, then you write a generic loader to load the level whenever necessary.
This was life before the level Editors like GLEED2D, what GLEED2D offered is basically something not far from the second way. in the second way you would have to write everything in plain text so you would have to imagine everything on paper and write the exact values of positions and properties in the .txt file to load it.
GLEED2D offered the GUI to do so without imagining anything , it’s basically a GUI based tool to design the level using your own textues/shapes/sprites and save the level in a .XML format then load the level from your game using also the GLEED2D.InGame Loader.
so, the process would be like this from your POV:
so, GLEED2D is one of many Level Editors which were ported successfully to suit WP7, in this case thanks to the great SteveDunn, who ported the Engine to WP7 and made the necessary dlls to include into your game.
in this blog post, I will try and help you out with setting up the GLEED2D Editor and I’ll help you set up a WP7 project to start loading a level into it.
you’ll be needing:
1-of course Visual Studio + XNA 4.0 Framework + Wp7 SDK
1- SteveDunn‘s GLEED2D for WP7 from here
2-the already built dlls to make it easy for you
3-any textures/images to start working with
Compiling and running the Editor
The .zip file you’ve just downloaded in number1, open \src\Gleed2D_Tool.sln , this will open the solution in a visual studio instance, press compile and run to run program
Now you need to compile and run the solution to have the following:
At the end of this post you’ll find a link to a youtube playlist of tutorials on how to deal with the editor step by step, right now I’ll just go to the Editors/Textures tab and select some textuers and place them inside the editor:
(you have to make sure that the textures’ positions doesn’t exceed the 480X800 displayable area on WP7 , note that the origin of the editor is in the center of the blue area)
After that you go to File->Save As and save the level you’ve just created.
Including the level and textures to your game
Now we’re going to start implementing the level into our sample game, first, go ahead and make a new project in Visual Studio, use:
File->new->project->XNA Game Studio 4.0->Windows Phone Game(4.0)
next, you’ll be needing to include the .dlls you’ve downloaded from number 2 in the resources:
You will now need to add the level you’ve just made using GLEED2D Editor into your Content folder , to do that, Right click Content->Add->Existing item->choose your level file
Do the same for the textures you’ve used in constructing the game levl, in my case the ‘grass’ texture.
Next, you’ll be needing to fix some properties in the .gleed file you’ve added to the content, go to the item properties, and do as the following:
There’s a problem with the resources position inside the XML/gleed file you’ve just added which I’m not sure how to fix it, so I do a simple hack to fix it, hopefully I’ll update this as soon as I find a regular solution.
The thing is the path the Editor adds to the textures is not the relative path inside your Content folder. To fix that use simple “Find and replace” to replace the wrong path inside the XML file with the right one from the Content folder, like this: (in my case the wrong one was ‘Users\Sherif\Desktop\WP7\Images\quick_grass.png’ and the right one is ‘quick_grass’ )
Now the file should be loaded and successfully implemented into your game.
Drawing the level contents into your screen
we’re now going to use the very easy very simple very unoptimized method to just draw the textures inside the screen, in order for the following instructions to work, you need to only be using textures (i.e pictures) in your level, further instructions for advanced implementation will be linked at the end.
what we did so far is that we made the XML file generated by the editor accessible by the game (i.e. it’s now one of the game resources), the next following lines will enable us to load, read and process the XML file contents to draw the level correctly.
add these namespaces to the beginning of your code:
Add the following line of code into the class of Game1:
Then you’ll need to add the following lines to load the level into the Level object:
Now, you have all the layers/items of your level inside the level object, we will now proceed to iterate through the level’s layers and items and draw them one by one (That’s why the following code won’t work if you have items that cannot be drawn i.e. shapes, paths…etc, but this is for the tutorial purpose only)
Voila, if everything went ok, you’ll be ending up with something like this:
Now everything works great, if you’re not a beginner in this, you sure know that I made some bad implementations in the coding part, I’m in the process of optimizing my code and designing some generic code to implement in each game, you can check this question for further overview.
Wooo, that was a long post 🙂 , I’m glad I finished it in only 4 hours , I was expecting more 😀
Special thanks goes of course to zissakos for creating this amazing tool , and gladly to SteveDunn for making the necessary porting to WP7, we couldn’t thank you enough 🙂
for further readings, please refer to:
GLEED2D for WP7
(Don’t forget to check the discussions/issues section on each website)
Playlist of GLEED2D Tutorials