XNA Code Generator for Tile Studio 2.55
Playing with XNA yesterday made me wonder how easy it would be to build a Tile based game, such as a 2D 'walk around' adventure game (ie; Zelda, or the likes). I downloaded a copy of Tile Studio 2.55 not too long ago and have been staring at it's icon on my desktop for quite some time now.
It came 'out of the box' with a handful of nice code generators, and it even included a .NET code generator ... but it only supported the BooGame library, and generated Boo code.
So, I thought to myself, why not look for an XNA Exporter ... so I loaded up the Tile Studio website, and found nothing there. I googled briefly and found nothing as well. So, I started on a little code adventure and decided to build my own. Now, keep in mind, I'm by no means an XNA Expert so my method for creating the tile map in C# may or may not be 'the best' or even 'proper'. However, the map works ... and I'm happy. I started on the project around 10:20am and am now writing this post at 11:50am ... so, it wasn't "too hard" and didn't take too much time. The time spent also included learning the Tile Studio Definition language and how it worked as well.
So, onto some 'proof', here's a few screenshots:
This is Tile Studio, with my little map loaded up
--the Map is 100x100, and the Tiles are 20x20.
Here is my Visual Studio project, after performing a code generation
in Tile Studio and refreshing the project directory and including the files.
And, here is my Map rendering to an XNA Game Window.
Now, in the project files shot you might notice that there are three files highlighted. The first is the exported Tile Map file from Tile Studio, the second is the actual Map definition (Tile2.cs) and the third is a helper class I wrote that is automatically exported for you that contains the MapDefinition and Tile classes.
And, here's the best part, your not gonna believe it ... or maybe you will. To load the map up, you simply do:
-
//In Class scope
-
WatrRoad map;
-
// in LoadContent
-
// in Draw
-
map.Draw(spriteBatch);
And that's it ... the MapDefinition provides a 'Draw' method to loop through all the tiles and render them to the screen. I've not yet optimized this to store a cached copy, but I also haven't tested it with any real 'logic' yet to try building a game. You can download a copy of the XNA C# Tile Studio Definition file from here, expect updates in the future to support more of Tile Studio's feature set.
Download the Definition File Here
Download the Full Example Project Here
Currently Supported Features:
- Export Tile Sets to BMP and place in 'Content' sub-directory
- Export CS File containing all Maps
- Export TileStudioMap.cs containing MapDefinition and Tile helper classes
- Easy Map instantiation, just pass a reference to the Map's Texture2D containing the Tiles
- Easy Map Rendering, just call the Map's "Draw" method and pass the SpriteBatch
Evil Clutches ala XNA, My First XNA Game
I was speaking with a co-worker last night, and we got into the topic of game development and XNA. As usual, I took the topic and went a little overboard and decided to install XNA at home and 'go at it'. Since I recently finished the 'Evil Clutches' chapter from Game Makers' Apprentice and, also released the 'Evil Clutches Javascript' version; I decided to attempt making Evil Clutches in XNA. It was a fairly straight forward process, and required almost no reading on my part. I was able to install XNA, Launch Visual Studio 2005 and create a new project and just 'begin'.
I was actually very impressed with how simple it was to build the game, so much so that I referred to it as 'childs play' to my co-worker just after finishing up the Alpha. With that said, here's the basic process I went through;
- Step 1: Launch Visual Studio 2005 and create a new Windows Game
- Add my Art resources to the Games' Content
- Create a GameObject base class to store common information (Position, Texture, Color, Collision Detection, etc).
- Create object classes for my Dragon, Boss, Fireball, Demon and Baby objects.
- Apply basic 'render' logic to the 'Draw' method of my Game class
- Apply basic 'call object Update' logic to my Update
- Create the necessary 'Update' methods on my object classes
- Revisit the Game's Update method and apply basic Input logic (Escape to Exit, Up/Down to move Dragon, Space to Shoot)
- Add a SpriteFont and add logic to print the score on the screen
- Package it up and Write this blog post.
It really was that simple, and the entire process took me less then two hours. Seriously, I banged the whole thing out just by looking up the 'How To' references on MSDN. Now, of course, as with everything in software development the 'easy ten step process' I listed above had lots of little 'inbetweens' (actual logic, etc).
You can download the 1.0.0.0-alpha release of my 'Evil Clutches XNA'. If there's an interest in XNA Game Development tutorials, then I might write up a 'The Making of Evil Clutches for XNA' post, so let me know in the comments if your interested in that sort of things.





