media partners
 
all partners


Get the latest Education e-News    
  • Microsoft's XNA: A Primer

    [01.18.07]
    - Alistair Wallis

  •  Benjamin Nitschke is the co-founder and lead programmer for exDream Entertainment, a German development studio who have released a number of titles, including Arena Wars and Rocket Commander.

    Nitschke is also a Microsoft Most Valuable Professional for DirectX, and has been a strong advocate of what XNA represents for developers and hobbyists alike. Through his weblog, he has written a number of tutorials for XNA development, as well as a number of reactions to his experiences with the GSE - not all of which, refreshingly, are glowingly positive.

    Currently, he is working on Armies of Steel with the company, as well as a book - Professional XNA Game Development - which is due for release in the coming months. We talked to him about his history with XNA and his experiences utilizing it to make games.

    What attracted you to XNA?

    Well, I've been a .NET game developer since 2001/2002 and have been working in C# now for over 5 years and never turned back to C++, except when I had to prove that the performance of C# is as good as C++. Since Managed DirectX (MDX) only came out in mid 2003 and was neither usable nor popular. I had my own OpenGL engine for Arena Wars already finished, so it took me a little longer to adopt to MDX, which I finally did in 2004 after Arena Wars, which was the first commercial .NET game ever with many innovative features: voice and webcam support, first person replays, and a really fun capture the flag RTS game overall.

    Managed DirectX is great and all and both Tom Miller, the main developer and architect for it at Microsoft, and ZMan (Andy Dunn) over at his popular thezbuffer.com website have pushed it as far as they could, but neither .NET game development nor MDX caught on until 2006. In the beginning of 2006 I released my Rocket Commander game with full source code and many video tutorials at Coding4Fun and www.RocketCommander.com, which was the first .NET 2.0 game and used MDX. Later that year, in August, Microsoft released the first beta of XNA and made everyone excited about homebrew Xbox 360 development, no matter if they were doing .NET development before, total beginners or just regular C++ game programmers.

    As an DirectX MVP I already knew about XNA a little bit earlier and was talking to Microsoft about possible XNA Starter Kits. For example ZMan, who is also an DirectX MVP, did the only currently available starter kit: SpaceWar. I myself started with a little racing game, which evolved very quickly to a very nice looking game and I would bet - thanks to this and maybe some other starter kits which will come out 2007 - this will be an interesting year. Later this year Microsoft also plans to release a more professional version of the XNA Game Studio IDE, which will even attract more developers to XNA and .NET game development.

    I'm very happy with the steps Microsoft finally took to make .NET game development a little bit more popular, a few years ago no one really cared about .NET, not even their internal DirectX or Xbox 360 teams, now everyone is excited. And for me it is a good thing to have a little bit more experience in .NET than all the other programmers out there, hehe.

    How have you found the learning curve for XNA?

    Well, hard to say for me, I was already a .NET developer for a long time. The adoption to XNA was very similar to [the change from] MDX to Managed DirectX for .NET 2.0, which I already did at the end of 2005, but MDX2 was dropped in April 2006 and never came out. The only hard thing was the console development in general, but that had not much to do with XNA, it is just the hardware and how everything works internally. For example a TV monitor does not display 100% of the pixels that are send out by the graphic card, it will cut off 5-10% at the borders and if you have any important user interface data there, it will just be not visible on most TV sets. Other things include the way post processing and render targets are handled on the Xbox 360, which can be a little different from the PC.

    Once you have understand all the differences it is very easy to just program on the PC and then test directly on the Xbox 360 (giving you a multi-monitor development environment for free). In the beta I had some comments on my blog about things I did not really like in XNA like the complicated content pipeline or the game components designer of the first beta, which was dropped anyway. Overall I'm very happy with XNA and I already use it for much bigger projects than XNA was developed for.

    Do you feel that XNA offers a good starting point for new programmers?

    Yes, absolutely. Thanks to the many available tutorials, good beginner sites, the hopefully better getting documentation - which is the only glitch in the XNA release in my opinion - and especially the upcoming starter kits even total beginners can quickly take existing code and make their own games in a very short time. Not only is Xbox 360 or console development actually possible for beginners, but XNA is also a very easy and fast to learn programming environment on the PC.

    What level of ability would you suggest programmers would need to be at to use XNA effectively?

    Most beginners will probably have difficulties understanding complex 3D calculations, having to worry about creating textures, shaders and cameras in 3D and this part is not really much different from Managed DirectX or a regular DirectX development in C++. Sure you can just use one of the starter kits or tutorials and play around with them, but if you have never programmed before you will have a hard time understanding all this at once.

    For that reason most beginners will probably start by developing some simple 2D games, especially arcade games, which can be a lot of fun. Professional game developers might take a look at XNA, but since you have to use the Express "beginner" version of Visual Studio 2005 right now for XNA game development, they will miss their advantages like all the plug-ins, source controlling, etc.

    If you have worked with DirectX or Managed DirectX before you can get quickly into XNA programming. Otherwise, it is possible to learn, but you need a few days to get the basic concepts.

    Are there any tips you would give to people using XNA for the first time?

    It helps a lot to look at one of the tutorials or starter kits to see how it is done. There is not much information about 3D programming in the documentation and if you have no idea about shaders and how to write them the XNA docs will not be the best way to learn them. If you are serious about game development and really want to do a nice looking 3D graphics engine, you should install the DirectX Software Development Kit and learn from the many samples available from there. I heard from many people that they are having problems getting the concept of shaders for the first time, so maybe it is best to read through some good chapter tutorials or buy a book about shaders. If you search my blog for books, I recommend a couple of shader books.

    Shaders might be another hard part in XNA at first, but since you don't have to worry about the fixed function pipeline anymore and everything uses shaders, it gets simpler after you understand the basics and it is much easier to add new shaders and cool effects later than it would in MDX. If you are just doing 2D games, you will never have to worry about shaders, because the SpriteBatch class handles all that for you.

    What do you feel the weaknesses of XNA are, and how do you work around them?

    I already mentioned a couple of things (docs, game components), but my main issue with XNA is just the content pipeline. It is easy to plugin textures or a few .X or .FBX models, but you can't reload them in your game. For any update you have to stop the game, recompile and let all content be processed again, and then start again. Sorry, that is not the way any game development team works. This practically forces you to work alone because your graphic artist cannot test any of the graphics he makes. On the windows platform you can load textures your own way, but that does not work with 3D models, which always have to be imported first.

    In my starter game I have around 100 MB of uncompressed content files and it really takes a long time to let them all compile and be processed and to even support nice normal mapping shaders the content importers for my .X files had to be extended to support tangent data generation and storing the used shader techniques.

    But in future projects I will not use the content pipeline anymore, I never liked it and it was always my biggest problem with XNA, it might be nice for smaller projects. It is very beginner friendly to just drag a few 3D models into the project and you don't have to worry about copying files over anymore or making sure that they are valid because everything is checked and compiled before you start your game. But if you don't really care about these advantages like I do, you want a more dynamic system that allows reloading while the game is running and letting the artists do what they can do the best: Take some crappy dummy graphics or 3D models from me and make them beautiful without me having to do anything!

    What challenges have you faced in porting existing games to XNA?

    I ported Rocket Commander to XNA a few weeks ago, it was my Christmas present to the XNA community. Thanks to the fact that Rocket Commander does not use many textures or models, it was very easy to just port them over to XNA. Well, I still had to re-export all 3d models because the tangent generation was quite a bit different - another big issue with the way the 3D models are exported, as many different 3D content creation programs do this differently - but the rest of the textures, shaders and effects could almost stay the same way.

    One final annoyance about XNA (I think I have mentioned them all by now) is the way music is handled. XNA uses XACT, which is Microsofts Audio Creation Tool for the Xbox 360 and Windows. It is really nice to create some sound effects quickly and modify them directly in the tool until they all sound nice and can be used in your game. But there is no support for any .mp3 or .wma files, all you can plugin are uncompressed .wav files and if you have 2-3 music files of 50 MB each your 10 MB game suddently becomes 100+ MB. Even with the available XMA (Xbox 360 only) and ADPCM (Windows only) compressions, you game will still be 3-5 times bigger than it would be by using .mp3 files.

    As an example, the source code for Rocket Commander using XNA is above 50 MB, while the original game is below 10 MB.


    Rocket Commander

    What advantages does porting games to XNA have?

    First of all there is the Xbox 360 compatibility, which is great for some games like the racing game I have done or Rocket Commander or the XNA Shooter game for my upcoming XNA book. All of these games are fun on the Xbox 360 and it is really cool to be able to just take your existing Windows code and let it run on a console. It gives you a completely different feeling about consoles, you suddenly feel more in control and you interact directly with it as a development system.

    Then there is of course .NET, which is the best programming platform available today, and why not use it for games? In the past MDX was not very popular, but XNA will grow much bigger and finally take over the world.

    What the hell am I talking about?

    For any .NET game developer it makes sense to adopt to XNA because MDX is not supported or updated anymore (last real update was in August 2005) and if you are a beginner, it really makes sense learning game development with XNA instead of working with a programming language like C++, which is almost 25 years old. Sure, a 25 year old car may still drive, but it is more fun to drive a new car and after you have t, it is cheaper to use it because it does not require as many repairs or as much fuel as the old car does.

    What issues have you faced in then porting games from PC to Xbox 360?

    I already mentioned this above. The only 2 issues I had were the visibility on TV sets (never draw anything important outside the 90% safe-region) and some issues with the RenderTargets. but both of these issues are just how the Xbox 360 works. The XNA Team did a great job keeping everything else in almost 100% compatibility, your games will just work on both platforms without having you to develop 2 different builds or messing around with hundreds of #if defines. You may want to add Xbox 360 game pad support to your game to play it correctly on a Xbox 360 and mouse devices are not supported on the console, but other than that everything works just great on both platforms.

    What do you feel the main positives of the content pipeline are?

    Main positives? Didn't you hear me rant about that earlier?

    Well, it is easy to use and for small projects or when you already have all the content data before starting development, it might be a good idea to use the content pipeline. But in my opinion it would be much better, if loading content directly would be supported in XNA. Gladly shaders and textures can be loaded dynamically on Windows, but for models I reimplemented my own model classes and I use collada files and binary imported files autogenerated from them to speed up the loading process. For everything right now and I will probably never turn back to the content pipeline for 3d models.

    How easy is it to have clean code using XNA?

    That is a trick question, isn't it? How easy is it to have a clean room? No matter how many things you have in your room or how big or small it is, if you just want it to be clean and organized you will just do it that way.

    XNA does help in keeping everything clean and C# is in general a very clean language, especially thanks to the code reformatting features of Visual Studio 2005 (or the Express editions). I have very strict rules for clean code, everything has to be in regions, each class should have its unit tests and the layout is always the same for all my classes (constants and variables first, then all properties, then the constructors and then all the methods that are used). I also comment all methods, fields and properties, no matter if they are public or not. I often have more than 2/3 comments in my code. I recently tested some code with some code analyzer tool and it told me that I have too much comments: what the heck?

    Anyway, I'm usually not very impressed by code from other people. Most of it is not commented at all and thanks to variable names like a, x, mbv, I have no clue what the code is about and since there are no unit tests either, I usually won't even bother looking through the code and compile it in my head.

    Maybe I'm getting old and don't think the same way as most other programmers anymore, but I think it is really a waste of time going through any code (not matter if written by you or someone else) that is not quickly understandable.

    How important do you think XNA is to homebrew and independent development?

    Microsoft currently pushes into this sector and it will stay important here because many schools and universities are starting courses about it. I get a lot of emails from teachers or professors asking me about helping materials for their courses. Hopefully my book - shameless plug again! - can help out with that too...

    How easy have you found engine integration with XNA, and what would you recommend for new users?

    I wrote a new engine, but I was able to reuse many components and helper classes from the Rocket Commander game. I have also 2 other main engines (one in DirectX and one from OpenGL that was used in Arena Wars), but they are above 200 000 lines of code and I will probably not port them anytime soon.

    I just have too many projects right now and my XNA graphic engine from the racing game is pretty powerful, so I use it for newer projects anyway.

    What do you think is most impressive about the games that you have developed using XNA?

    Hmm, the shortened development time is pretty impressive I think. I have never seen a nice looking 3D racing game that has been done in just 4 weeks before and the other starter kits and games I have seen so far looked also pretty impressive and had a short development time too. I already proved with Rocket Commander that it can be easy to create a game in a matter of few weeks in .NET. My guess is that it will take a while (2-5 years) until the real revolution happens in the game programming world and most people are using .NET instead of most people still using C++, like right now. By then a new programming language will probably be out and I will be the first one using that as well!

    What do you find most exciting about XNA?

    I would say the future of XNA. No one really knows how far it can take game development, not even the XNA Team at Microsoft. They have some clever people there and even some former professional game developers, but even they can't say if XNA Game Studio (the professional version coming out later this year) will catch on immediately or if it will take a while or if XNA will still be used mostly by beginners and for homebrew development. Who knows?

    But this is what I'm feeling the most excited about. There is no point for me being excited about XNA anymore because I already know it will be my main game development framework in the future and I have written all kinds of MDX, C++ and DirectX and OpenGL engines and games before. My last non XNA project will probably be Arena Wars Reloaded, the successor of Arena Wars coming out in a few months. It is still written in OpenGL and .NET and features many cool features, especially a new shader engine, but it would just be too much work to rewrite everything to MDX or XNA.


    Arena Wars Reloaded

    What inspired you to begin writing Professional XNA Game Development?

    An editor from Wiley just asked me and I said, "Yeah, why not". Just like you asked me for this interview. I sometimes say yes to too many projects at once and then I end up doing three to four full-time projects at the same time, which is not healthy at all.

    Who is the target audience for the book, and what can readers expect from the book?

    The title says Professional XNA Game Development to attract even professional game developers. My hope it the book can be useful for C++ programmers that might have worked with DirectX or games before and are just interested in this new XNA thingy.

    The book does start with very simple topics however and leads the reader through the creation process of 7 different games. Thanks to the many games and the full source code for them the book chooses a very practical approach while each chapter still covers something new about XNA or game development in general.

    The book does start with simple 2D games and explains for the beginners how to get started, but then before you know it a full-blown 3D engine is being developed in the game and the reader learns all about 3D engines, shaders, 3D models, normal mapping and post processing effects. With that knowledge several advanced games are developed and more topics of XNA are covered like AI, sound, game logic, etc. In the final part of the book the advanced topics like writing a physics engine, doing shadow mapping and so on are discussed, so everyone should find something useful in the book.

    What future plans does exDream have in regards to XNA?

    We are going to develop our next-gen game engine in XNA, but we have also build in a compatibility layer for Direct3D 10 and most of it is still in MDX, but will be ported to XNA in the future. We are currently focusing our attention to Arena Wars Reloaded, but after that a bigger and mind-blowing big RTS game is going to be developed - well, again, we are working on that for the last year too!

    Where would you like to see XNA going in the future?

    I'm just waiting for XNA Game Studio Professional and I hope more and more people are attracted to XNA. The XNA community is already a very friendly and helpful community that provides a lot of free source code and maybe it will even stay that way when more professional game developers join us making the world a better place by sharing more code!