My PhotoBruno Brás Silva

09, April 1986

info@brunosilva.net

Sintra Lisbon Portugal

Multiplatform Games in XNA - Preprocessor Directives

Posted on 7:25pm 6/22/2008 by Bruno Silva in .NET, Programming, Visual Studio, XBox 360, XNA

You probably already know that developing a game that runs both in XBox 360 and Windows is possible and pretty manageable using XNA Game Studio. If you start developing your game for Windows (which is great to compile/debug your code more quickly), you can then duplicate that project as an XBox 360 game. The same files will be used, but during compilation, the assemblies of XNA Framework that are used are chosen based on the target platform.

Create Copy of Project fot XBox 360

Developing a game for both platforms isn’t that trivial. There are a lot of functionalities that are exclusive to each platform. For instance, the Gamercard integration that I talked about in an earlier post, only works in XBox 360. In the other hand, since XNA games targeting Windows are pure .NET managed code, you can use whatever .NET libraries you want (such as WiimoteLib :) )

If you have a game that you want to compile to both platforms, but which has slight differences, you can use the C# Preprocessor Directives. When you create an XBox 360 project, the XBOX and XBOX360 conditional compilation symbols are used by the preprocessor.

XBox 360 Project Properties

Those symbols can be used to create conditions that make the preprocessor able to choose which lines of code of a file to compile. The example bellow is pretty self-explanatory.

Preprocessor Directives

If you compile this game targeting the XBox 360 you’ll get a blue background, otherwise you’ll get a red background.

This is not a XNA or XNA Game Studio feature, but this was the first time I needed to use such feature. More information about C# Preprocessor Directives are available at MSDN.

Leave a Reply

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

© Bruno Silva | Powered by Wordpress