Casual game developers have been using XNA since 2004 for ease of create games for Windows, XBOX and most recently Windows Phone. XNA is a .NET framework for game development providing a content pipeline and load functionality for game asset, animation, math, sound and user input tracking via gamepad, mouse, keyboard and touch with game logic organized in a straightforward game loop architecture.
Game development is not trivial undertaking and XNA was a great framework to start down the path for a great number of novice game developers and/or students and developers who wanted to learn how to create quality game applications. XNA along with Visual Studio made it as easy as File –> New –> XNA Game Studio Project and you were off and running.
MonoGame is an open source cross platform implementation of the XNA namespace and class model. The goal of MonoGame is to provide XNA developers with a framework to build applications that will run on Xbox 360, Windows, Windows 8, and Windows Phone while providing the ability to port the game using the same C #codebase to run natively on the iOS, Android, Mac OS X, and Linux platform with minimal effort. With these goals in mind, the MonoGame motto therefore is to “Write Once, Play Everywhere”. The technologies that make the MonoGame API cross-platform power possible are:
- OpenTK – a low-level C# library that wraps OpenGL, OpenCL and OpenAL for 3D graphics.
- SharpDX – an open-source implementation of the full DirectX API for .NET which allows for development of high performance games, 2D and 3D graphics rendering, and real-time sound
Lidgren.Network – a networking library for .NET framework which uses an UDP socket to provide an API for connecting a client to a server, as well as, reading and sending messages
The game you will be making in this walkthrough is using the MSDN Shooter tutorial. Shooter is a particular type of game with a set of well-defined limits around what it does when the user interacts with it. This tutorial is a good starting point for learning game development with XNA and publishing a game running on Windows 8 platform using XNA leveraging MonoGame. In addition to leveraging this technology for Windows 8, you can use the MonoGame technology for native cross-platform development with other mobile platforms.
Setting Up Your Development Environment
Before you can write games for Windows 8 using MonoGame, you mush setup your enviroment and your IDE to do so. I have outlined the steps below for getting your environment created. Please follow and perform the following steps in the order stated to successfully prepare your computer for XNA Development with MonoGame:
Install Microsoft Windows 8.
Install Games for Windows
Install Windows Phone 8 SDK or Visual Studio 2010 Express for Windows Phone
Why do I need Visual Studio 2010? There is a feature of XNA called the Content Pipeline, a pre-compiler step in the preparation of graphic and audio assets for use at runtime in XNA. This feature is not implemented in MonoGame. You can leverage VS 2010 or VS 2012 with the Windows Phone SDK installed to leverege the XNA Framework template to compile the graphics into the .xnb files to include in your Windows 8 project.
Install Visual Studio 2012 for Windows 8
Visual Studio 2012 Express: http://bit.ly/QvLWLX
Visual Studio 2012 Pro/Premium/Ultimate: Use DreamSpark, MSDN or your licensed copy
Install MonoGame 3.0 binaries, templates, and dependencies with Windows Installer:
Leverage the new MonoGame 3.0 Windows Installer to install the MonoGame and SharpDX libraries needed to create an XNA 4.0 project for Windows 8. This will also install two MonoGame templates for use within Visual Studio to start an XNA/MonoGame project.
Optional: Install GitHub
If you want to review the MonoGame Source Code or contribute code to the MonoGame project.
Create a MonoGame project
Windows 8 is designed to run on a variety of devices, including tablets and other devices that, through the aid of on-board sensors, know whether they are in landscape mode or portrait mode. XNA Game Studio 4.0 Refresh is a programming environment that allows you to use Visual Studio to create games for Windows Phone, Xbox 360, and Windows. XNA Game Studio includes the XNA Framework, a set of managed libraries designed for game development based on the Microsoft .NET Framework. In order to leverage the power of XNA for Windows 8 since it is not supported natively, we will leverage the MonoGame framework.
Step 1 – Create a MonoGame project and set references
Open Visual Studio 2012 and select New Project. Under Templates, select Visual C#, you should see the MonoGame project templates listed. Select the MonoGame Game (XAML). Name the project Win8ShooterGame and ensure that the option to Create directory for solution is checked/selected.
Figure 1 – Visual Studio with MonoGame Templates
Step 2 – Set a MonoGame references (Optional)
**Follow these Steps ONLY if you Installed MonoGame Directly from GitHub or have problems with Template pointing to correct MonoGame references. If you installed via the MonoGame Installer, please skip to Step 3. **
Now we need to ensure that the Solution has the correct references to the MonoGame Framework and its dependencies. Right click on your solution in the Visual Studio Solution Explorer and select Add, Existing Project.
Figure 2 – Add Existing project to Solution
Browse to in Explorer to C:\Users\[you]\Documents\GitHub\MonoGame. Select the folder named MonoGame.Framework. In this folder, you will find the MonoGame Windows 8 CSPROJ project file in this directory: C:\Users\[you]\Documents\GitHub\MonoGame\MonoGame.Framework\MonoGame.Framework.Windows8.csproj. Select this project and click Open.
Figure 3 Add MonoGame Framework for Windows 8 project to Solution
Once the project has been added to the Visual Studio solution, right click on the MonoGame.Framework.Windows8 project, and select Clean. Then right click on the project again, and select Build. You may see a few warnings once you build the project, but that is okay.
Now select the Win8ShooterGame solution, select References, right click and select Add Reference. In the Reference Manager, we need to add the reference to the MonoGame.Framework into the Windows 8 project by selecting Solution and then Projects. Select the checkbox beside the MonoGame.Framework project. Click OK (Figure 4). Then again go back into Reference Manager and add the MonoGame Framework Dependencies by selecting Browse. Browse to location: C:\Users\[user]\Documents\GitHub\MonoGame\ThirdParty\Libs\SharpDX\Windows 8 Metro and select all of the .dll files within the folder.
Figure 4 Add MonoGame Framework and SharpDX reference
Finally, select the Win8ShooterGame and right click. Select Project Dependencies and select the checkbox next to MonoGame.Framework.Windows8. Click Okay and Rebuild the Entire Solution. You may get warnings, but if you have followed the steps correctly, there should be no errors.
Figure 5 Add MonoGame Framework Project Dependency
Step 3 – Test MonoGame Environment
Now, let’s test to see if your MonoGame environment is set up correctly by running the application either via Local Device or and via the Windows Simulator. If your setup was successful, you will see the Cornflower Blue background commonly created by default with the XNA Framework projects.
You are now ready to start building your Windows 8 game. In Part 2 of this series, we will add the first asset to be used in your Windows 8 Game, a player object. The player which will be represented as a spaceship will be the primary source of control for the first player shooter game. In Part 2, we will create and build a player class object to represent the actions and properties associated with the spaceship for the game.