GAME JOBS
Contents
From XNA to MonoGame
 
 
Printer-Friendly VersionPrinter-Friendly Version
 
Latest Jobs
spacer View All     Post a Job     RSS spacer
 
June 6, 2013
 
Wargaming.net
Build Engineer
 
Gameloft - New York
Programmer
 
Wargaming.net
Build Engineer
 
Virdyne Technologies
Unity Programmer
 
Wargaming.net
Quality Assurance Analyst
 
Wargaming.net
Python Developer
spacer
Latest Blogs
spacer View All     Post     RSS spacer
 
June 6, 2013
 
Free to Play: A Call for Games Lacking Challenge
 
Cracking the Touchscreen Code [1]
 
10 Business Law and Tax Law Steps to Improve the Chance of Crowdfunding Success
 
Deep Plaid Games, one year later
 
The Competition of Sportsmanship in Online Games
spacer
About
spacer Editor-In-Chief:
Kris Graft
Blog Director:
Christian Nutt
Senior Contributing Editor:
Brandon Sheffield
News Editors:
Mike Rose, Kris Ligman
Editors-At-Large:
Leigh Alexander, Chris Morris
Advertising:
Jennifer Sulik
Recruitment:
Gina Gross
Education:
Gillian Crowley
 
Contact Gamasutra
 
Report a Problem
 
Submit News
 
Comment Guidelines
 
Blogging Guidelines
Sponsor
Features
  From XNA to MonoGame
by Dean Ellis [Programming, Game Developer Magazine, Console/PC, Indie, Smartphone/Tablet]
12 comments Share on Twitter Share on Facebook RSS
 
 
May 15, 2013 Article Start Previous Page 4 of 6 Next
 

Tweaking MonoGame for Mobile

So you have a great Xbox 360 or Windows game that you want to port over to a mobile platform. What kind of things do you need to worry about? There are some obvious ones that will come to mind first: screen size, input, and performance. Here's how to handle those factors with MonoGame.

Screen Resolution

With certain platforms, like Windows Phone 7 and iOS, you can almost guarantee the screen sizes of the devices you are going to be working on, but with some devices and platforms it's not so easy. Windows Phone 7/8 support hardware scaling, but with Android, Ouya, Windows 8, and the Retina displays on iPad and Mac, MonoGame developers need to take into account the various resolutions they might come up against. Sometimes you'll find yourself navigating a minefield of screen resolutions ranging from 320x200 all the way up to full HD.



One technique that has been used quite well in the past is to use SpriteBatch scaling. With this method, you can design your game to run at a particular resolution, then at run time figure out a scale matrix that will resize your game to match the actual screen size of the device you are running on. This matrix can then be passed to the SpriteBatch, which will scale your graphics. In the following code, we can see some sample code for calculating the scale matrix; in this case our

virtual resolution is 800x600.

var virtualWidth = 800;

var virtualHeight = 600;

var scale = Matrix.CreateScale(

(float)GraphicsDevice.Viewport.Width / virtualWidth,

(float)GraphicsDevice.Viewport.Height / virtualHeight,

1f);

With that matrix calculated, we can now call spriteBatch with the extra matrix parameter like so:

spriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, scale);

// draw stuff

spriteBatch.End();

This will apply the scale matrix to the items being drawn in that batch. There are other considerations like aspect ratio and letterboxing that you need to take into account, but there are plenty of resources out there, which were originally written for XNA that can be reused in MonoGame and applied to new platforms. (For more on this topic, read this post.)

At a certain point, however, scaling won't solve your problems. Scale down too much and your graphics will become pixelated; scale up too much and they become blurry. At this point, you need to start looking at the assets. One technique you can use on iOS is have two sets of assets -- one for normal displays, and one for Retina displays. You can do this by adding a @2x suffix to the name of the larger asset and including that asset in your game package. The MonoGame content pipeline has been coded to make use of this trick on iOS, so if you have a raw asset or .xnb file which has a @2x version and you are running on a Retina display device, that higher-resolution asset will get loaded. All the developer needs to do it include those assets in the application. (This does make your app package larger, unfortunately.)

The other option is to have two versions of the game, one for normal and one for HD, each with different scales of assets. This way, people have the choice of downloading a larger high-definition game or the smaller normal one.

Handling Input Devices

Moving between platforms means you need to support various input devices. On the desktop platforms (Windows, Linux, and Mac), MonoGame uses the Simple Direct Media Library (SDL) to interface with the various joysticks and gamepads that might be available. The inputs from these devices are routed through the GamePad class. SDL does seem to have a problem reading the USB description of some of the Xbox 360 controllers, so on occasion it will fail to apply the correct configuration.

Mouse and touchpad input is one area where MonoGame has diverged from the normal XNA. On Windows Phone 7 and 8, if you use the XNA implementation provided by Microsoft, all of your touch events will be routed through to the mouse as well. This can make it very easy to port games over from Windows and Xbox 360 to those platforms. However, with the introduction of Windows 8, you now have devices which can have a mouse and a touch screen, and it is possible that game devices will want to use these separately. With this in mind, if you have a Windows game that you are porting to a Windows Store App, you will need to add support for touchscreens as your existing mouse code will not be used. 

 
Article Start Previous Page 4 of 6 Next
 
Top Stories

image
Keeping the simulation dream alive
image
A 15-year-old critique of the game industry that's still relevant today
image
Advanced audio streaming in Unity
image
Amazon launches dedicated indie games storefront
Comments

Thomas Happ
profile image
I've been trying to determine if monogame is compatible with the Playstation Mobile development kit (which is also C#). I think that would be quite handy given Sony's recent indie push!

Tom Spilman
profile image
MonoGame does have PSM support.

Kevin Gadd
profile image
We're using MonoGame on PSM right now. It's way better than trying to port from scratch.

Pedro Kayatt
profile image
Would like to suggest to take a look into the Cocos2d-x for XNA. People have been using it with MonoGame with success and porting the game to as many platforms as you would like!
XNA is good, don't get me wrong, but using a simple engine to take the best of it seems to be the best!

David Amador
profile image
Nice article. and thanks for the plug to my blog :)

Cheers

David Keyworth
profile image
XNA's always been awesome, but now that it's completely cross-platform it's been pretty cool to see all the professional games coming out of a managed C# environment.
Sadly, given that even a basic, clean-installed content-project setup on Windows gives all sorts of warnings and errors for me, I'm under the impression that MonoGame is essentially still an "early development" product that takes quite a lot of effort for an amature coder like me to get running smoothly. I may start my future projects in Microsoft XNA, hoping that the Mono project matures a bit further in the near future, for the ease of usability Microsoft's project has.

Curtis Turner - IceIYIaN
profile image
Shows about 3,000 games on XBLIG:
http://marketplace.xbox.com/en-US/Games/XboxIndieGames?SortBy=ReleaseDate

On Windows Phone I have no idea. Windows Phone 8's can use something other than XNA:
http://www.windowsphone.com/en-us/store/top-rated-games

On Windows it doesn't seem like many XBLIG crossed over. However, the prices for these games are slightly higher.

I suggest developers try and get different resolutions and input methods into their games.

Robert Schmidt
profile image
Anyone ever heard of Silversprite? I've been burned too many times by ambitious open source projects that run out of steam after people have invested a great deal into them. Unity3D is a cross platform version of what XNA should have been. I recommend new game developers invest their time in that.

Wendelin Reich
profile image
Not for the first time, I had to think about how open source tends to fail in the games area. Of course, I would love to see MonoGame succeed, but I'm not naive enough to bet my money (i.e. my time) on it.

Is the problem that games are so hardware-dependent? Even _huge_ open source projects such as the Linux kernel tend to have problems keeping up with hardware evolution (and thats one reason why Linux and games is still a problematic combination).

Or is the problem that game developers have strong economic incentives not to share full-fledged, working code projects? If so, then why does open source work in other areas of IT?

Yet another reason is that game developers have unusually high demands on software reliability. People will accept if OpenOffice crashes (it has auto-save), but a game that crashes tends to be a HUGE turnoff to users. Perhaps thats because (often) games have so extremely complex internal state, which is difficult to reproduce (either for the user via replay, or via a sufficiently fine-grained auto-save).

Dylan Wilson
profile image
MonoGame has a very unique market in that existing XNA developers can port their games to many other platforms including Android and iOS with relatively little effort.

Comparing it to Silversprite isn't even in the same ballpark. Unity3D is a perfectly fine option for developing games but it's not direct competition for MonoGame. Unity3D is a full game engine, whereas MonoGame is a replacement for the XNA framework. They solve different problems.

Brian Perry
profile image
I started out being very excited that I could develop XNA games using mono-game from linux using mono-develop. After doing a simple game though, I realized that you needed a windows machine in order to put art into mono-game. If your developing on Mac or Linux then, your out of luck. They said they were developing an art pipeline for mac and linux so I guess I have to wait until then.

Dean Ellis
profile image
Believe it or not SilverSprite is kind of the GrandFather of MonoGame :)

As for Mac development as the article says you can make use of raw assets like png etc, there are only a few content types where you MUST use the content pipeline, fonts and effects are the main ones.


none
 
Comment:
 




UBM Tech