Archive for November, 2012

This is the start of a series of posts about getting started developing games using MonoGame in C# for Windows 8. One thing I think I need to make clear is that MonoGame on Windows 8 does not run on top of Mono, it runs on top of the WinRT C# stack and SharpDX, a free open source library that allows you to access DirectX from C#. This means you don’t have to purchase any Mono licenses to use MonoGame on Windows 8, and MonoGame itself is free and open source. If you decided to port your games to iOS or Android then at that point you would need to license the appropriate Mono tools from Xamarin.

The Tools

For Windows 8 Store development you’ll need to be running Windows 8. You can do a 90 day trial here http://msdn.microsoft.com/en-US/evalcenter/jj554510.aspx?wt.mc_id=MEC_132_1_4 if you don’t have other access to Windows 8. You’ll also need Visual Studio 2012. There is a free Express version for Windows 8 available at http://www.microsoft.com/visualstudio/eng/downloads#d-2012-express if you can’t get a paid version of Visual Studio 2012. It can install side by side with Visual Studio 2010 if you need both environments.

After Visual Studio is installed, you’ll also need MonoGame. For this series I’ll be using the MonoGame 3.0 Beta that you can install via this link http://monogame.codeplex.com/releases/view/96421. The installer will also install a matching version of SharpDX and any other supporting libraries. As MonoGame 3.0 moves to release I’ll try to update this blog series to use the latest version.

File –> New –> Project

When you install MonoGame it will add two project templates to Visual Studio 2012. So let’s do File –> New –> Project and choose the MonoGame Game (XAML) template. Name it MyFirstGame.

image

The difference between these two templates is that the one we chose allows you to overlay XAML visual elements on top of your game surface. This is something you don’t want to do indiscriminately since it can impact performance but it’s a great way to be able to add things like the Settings pane flyout and an Application Bar if necessary. It also helps when you want to add XAML based advertising controls. The other template is pure MonoGame and you wouldn’t be able to overlay any XAML elements. I have a hard time thinking of any reason why you would want to use the non-XAML template and I would recommend you always use the template that allows you to mix MonoGame and XAML.

One the game is created you can go ahead and run it. You should see a screen that’s a light blue, known as Cornflower Blue. This is a famous color in XNA development, and some claim it is a reference to dialog in Fight Club. Whatever the reason, I like to call this the “Blue Screen of Life” because it means that everything is installed and configured correctly to start with game development.

I find it useful to take advantage of the Simulator that ships with Visual Studio 2012 when debugging. In the Debug toolbar, where it says “Local Machine” you should be able to select “Simulator” from the dropdown menu.

image

This option allows you to run a copy of your current environment but run it inside a virtual machine. Some advantages include easily swapping between Visual Studio and the Simulator, spoofing things like location services, taking screen shots, testing different resolutions, and more. Running inside the Simulator looks like this:

image

If we take a look at the GamePage.xaml you’ll see that it doesn’t look like a normal page in a XAML based Windows 8 Store application. Instead it has a root element of SwapChainBackgroundPanel.

image

The SwapChainBackgroundPanel is what allows you to overlay XAML on top of DirectX.

The other important file is Game1.cs. This is your game class and all game logic and rendering will either be in this file or in a file called from this file. If you have an existing XNA game, you should be able to take this file as-is and replave Game1.cs with this file and things should “just work”. Actually this isn’t exactly true and you’ll also have to concern yourself with bringing in any Content that the game needs. In the next post we’ll look at bringing in content and drawing something to the game surface.

This is the first (zeroth) post in a series on getting started using MonoGame to create a Windows 8 Store game. Unless you want to spend the money on a Unity3D license, I think it’s the best option available for a hobbyist C# game developer to create a game for Windows 8.

A little about me

Back in the early 1980s, I was in middle school and my older brother convinced my parents to get a home computer. That was the Texas Instruments 99/4a and almost immediately I started trying to create my own version of Donkey Kong using user-definable character graphics. That didn’t go too well but I learned a lot, and eventually wrote some of the more popular third party games for the platform as a high school student.

Then I went off to college but still loved gaming. When learning a new programming language I’ve always found I learn it best if I write an application using it. So when I was learning C, around the same time I really got into MUDs, specifically GrimneMUD that used the DikuMUD engine. To connect to a MUD you would use the Telnet protocol, but there were “MUD clients” that would give you more functionality on top of raw Telnet. I tried a few MUD clients, but there was a simple but powerful one called TINTIN created by Peter Unold that I preferred but there were things it didn’t do that I wanted. So started extending and rewriting TINTIN in an effort to learn C better and I called my version TINTIN++. It went on to become one of the most popular MUD clients of all time (hey it even has its own Wikipedia page!).

A few years went by where I got away from game development and focused on business apps. At some point I started playing Flash based games and had the urge to get back into game development so I looked at writing games in Flash. I went out and bought a book “Beginning Flash Game Programming for Dummies”. It was a good book, but I never really got the hang of Flash. A couple of months later Microsoft released XNA, and there was no looking back. I was using C# for my day job, and the ability to use it to create games lured me in. I became a Microsoft MVP in XNA by helping out in the forums and blogging about learning how to program using C# and XNA.

Then Silverlight came along and I was enamored with it, and wanted to leverage my XNA skills in Silverlight. This led me to create SilverSprite, an open source library for Silverlight that implemented the XNA API. When I started I didn’t even know if it was possible, but I decided to give it a shot to see if I could make it easier for XNA developers to get their games running on the web.

So why am I going on about this, and what does it have to do with MonoGame? It turns out that MonoGame is a descendant of SilverSprite, and without me pioneering the way with SilverSprite, MonoGame may not have come about. I feel like the proud Godfather (or maybe more accurately the crazy Uncle) of MonoGame and I couldn’t be prouder of how it has grown and I’m thrilled to be involved in a small way in that process.

A little about MonoGame

MonoGame started out as XNATouch, an open source library on top of Mono for iOS. It evolved into a powerful XNA compatible library for iOS and Android for both 2D and 3D games, and many successful games have been deployed to these platforms using MonoGame.

When Sickhead Games wanted to bring their popular XNA based Windows Phone game ARMED! to Windows 8, they were faced with the problem that Microsoft wasn’t supporting XNA for Windows 8 Store apps. After exploring their options, they determined that porting MonoGame to Windows 8 was their path of least resistance and took on the task of porting MonoGame as they brought their game to Windows 8. They have done a phenomenal job and ARMED! is currently available on Windows 8 and is very impressive. They are not the only MonoGame based game on Windows 8, however, and there are many others including Geared and Draw a Stickman.

Along with XNA not being supported for Windows 8 Store games, it’s also not supported for Windows Phone 8 games. You can still make Windows Phone 7.x games in XNA but can’t take advantage of any Windows Phone 8 features. From what I understand there is a Windows Phone 8 version of MonoGame currently in the works.

A little about this blog series

I’ll be expanding upon my session from Tampa Code Camp about getting started with MonoGame for Windows 8, which was originally based on a session I did this spring on XNA for Windows Phone. So if you’re impatient you can jump ahead and get the slides and source code for that session here: http://www.billreiss.com/monogame-for-windows-8-session-from-tampa-code-camp/

I hope you find this series useful and that you have as much fun with it as I have.

There’s been a lot of talk about new features in Windows Phone 8, and it’s been getting positive responses in general, even from the Verge and other outlets that have been very critical in the past. The one place they still ding Windows Phone consistently is on the ecosystem. There are apps/games available on iOS and Android not available on Windows Phone and many times it’s a killer app that people can’t live without.

 

One of these apps is Pandora. I have a very big suspicion that the major reason it wasn’t ported to Windows Phone 7 was because they would have to move to managed code (C# or VB.NET), and this was just too big of an undertaking for them. Sure, other apps did it, but I suspect in most cases it was either an influx of cash from Microsoft, or Microsoft itself doing the port. I know when I worked on the iHeartRadio app for Windows Phone 7 we used absolutely none of the code from their existing apps and started fresh.

Windows Phone 8 no longer requires that apps be written in .NET, you can now use C++. When tech pundits talk about the lack of ecosystem they are basing that on the history of Windows Phone 7, but I really think that the changes made in Windows Phone 8, especially the ability to write apps and games in C++ makes a huge difference and now I think you will see Windows Phone be a first class citizen with developers because they won’t have to do nearly as much to support the Windows Phone platform.

Add to this the fact that Visual Studio is the absolute best development environment on any platform, and it’s very possible that we may see some apps on Windows Phone first, followed by iOS and Android. Of course this won’t be the norm, and I’d be happy if we see apps at the same time or not long after.

Of course ideally we would see some killer apps on Windows Phone first, and with the increased options for development there is a much better chance this could happen. Overall I think that Windows Phone 8 has the absolute best development environment of any smartphone in the industry, and I hope and expect that this will translate into a thriving ecosystem. Only time will tell.

By the way, I have two Windows Phone 8 devices now after my recent visits to the Windows Phone launch in San Francisco and at the BUILD conference and personally I’m very impressed with the platform, animations are smoother, most of the major drawbacks have been resolved, and the hardware is up to spec with the other flagship smartphones. I’m very excited to see where this goes.