Alexander Smirnov

Monogame/XNA Examples v2.0

16 posts in this topic

Let me introduce a series of essential monogame/XNA tutorials and examples that are definetly will come in handy for the begginers. I've planned this stuff a while ago, so it will be updated from time to time as my own research in the area goes on (and of cause i have some free time). 
If you have any suggestions or ideas about my examples please feel free to discuss them. This work is my open-source contribution to the community.
The current version of examples solution includes the following:

  • Independent resolution renderer (IRR). One of the main cross-platform development problems is the problem of optimization of the displayed content on the variety of different devices with different screen resolutions. IRR is one of the simpliest solutions for such problems. It automaticaly scales rendered content according to custom "virtual" screen resolution maintaining defined screen width/height ratio. Though huge scales probably can cripple your textures it is possible to implement additional techniques to load different sets of the textures (high res/low res)  for different resolution ranges. This IRR is based on the work of other author (all copyrights are preserved) but modified for better usability and features support. Be sure that it will be updated to better accomodate all of the example projects.


- Screen auto scaling to fit any resolution with any aspect ratio

- Single virtual screen resolution space that makes you to store only one coordinates set valid for all resolutions

- Easy objects selection and coordinates conversion

  • UI Designer Component. By the time i've spent making my first game i've runned into the small but nasty problem. This is the problem of making the good looking UI with ease and this is the problem even in case you already have some nice textures. My little component saves your time by allowing you to place a list of textures on the screen and arranges them as you like alowing to change texture position and size. After the composition is done you can copy pos and size data for each texture right into the clipboard (Thanks WinForms!). And bear in mind that if we'll use IRR from the first example we get virtual coordinates that are valid for all resolutions at once.  Recently, i've also added helper WinForms window that provides easy textures and names management, now you can load/remove/dupe textures on the fly and generate coordinates code for all textures at once. Nice? I bet it is! :)

- Load/remove/duplicate textures on the fly from source images

- Place and resize textures using mouse, keyboard and input fields

- Change textures drawing order, names and coordinats using WF support window

- Get generated textures rectangle code right into your clipboard

- Compatible with independent resolution renderer

  • Advanced Camera2D. A must have for any 2D game! Camera2D concept allows to perform common zoom, pan and rotate operations on all textures that is drawn using this camera. My camera example also provides additional features such as smooth camera transition to coordinates, smooth coordinates follow logic and rectangle area zoom. This camera is intended to be used with IRR so basicaly the order of coordinates transformation is: IRR matrix -> Camera matrix -> Onscreen result!

- Zoom, pan and rotate affected textures

- Smooth transition to specified position

- Smooth object follow camera using transition

- Zoom to rectangle area

- Easy objects selection and coordinates conversion

- Compatible with independent resolution renderer


  • Sprites example. Sprite class is commonly used to incorporate and make easier different operations with the textures. This is my own implementation of Sprite class that provides such features as:

- Multiple textures storage each with own properties such as Visibility, Scale, Rotation, Origin, Transparency, Depth, etc.

- Different texture types: SpriteTexture (used as the main texture ) and DecalTexture (used as the decoration texture that is bound to sprite rectangle and scaled/rotated automaticaly)

- Interface based structure that allows to easily implement different sprite classes (TODO: SimpleSprite and AnimationSprite examples)


  • Particles example. Particles will come in handy when you decide to make some nice special effects for you game. For example gun/laser shots, smoke, rocket trails and explosion. Possibilities are limitless. In this example there are a couple of classes that are compiled in a mini particles engine that performs centralized particle logics handling and takes care of basic stuff like particle update/disposing and universal rendering. Also there are some custom logic classes included for different special effects. Component classes are:

- ParticlesManager - static class that manages particle logic objects and draws particles.

- ParticlesLogic - base abstract class for custom logic object that implements particles storage, TTL tracking and handles particles creation using input properties.

- Particle - particle class that contains all basic particle properties such as Texture, Position, Direction, etc.


Some helper classes that will be definetly improved with more examples to come:

  • InputHelper class. Simplifies input management for a variety of devices across many platforms. You can see its actual usage in my examples. Some parts of the code i've got somewhere from the web, unfortunately i don't remember where exactly...
  • ResolutionRenderer class. So its the same IRR from the first example used in all my examples.
  • Extensions class. Holds different extension methods for monogame classes. Mostly SpriteBatch class extensions for method calls simplification.

Version history



+ Improved Monogame v3.2 support
+ Added UIDesigner cleanup routines
+ Added UIDesigner ability to load XNB files (texture only)
+ Added particle explosion to Example 5
+ Added Camera2D::ToDisplay() method for virtual to screen coordinates translation
+ Added ResolutionRenderer::ToDisplay() method
+ Some code refactoring 
+ Improved IRR to be less garbage intensive
+ Added Example 5 - Particles
+ Added additional checks in UIDesigner
+ Added SDL.dll file to solution for easier integration using new MG installation
+ Added missing license notes :D
+ Added Example 4 - Sprites
+ Fixed UIDesigner bug where textures hasn't been copied properly
+ Added the ability to change textures draw order using WinForms control
+ Added some tooltip to WF control
+ UIDesigner enhancements
  • Added constructor option to hide tutorial text
  • Added class property to hide red tint on selected texture
  • Added mouse resize saving aspect ration (using SHIFT + RMB)
  • Optimized logic to work with delayed texture loading (null Textures prop)
  • Fixed bug with coordinates not updated after texture list change
  • Made mouse drag to work only if directly clicking on texture

+ Added optional WinForms helper control for UIDesigner that allows

  • On-the-fly textures and names managment (load/remove/duplicate)
  • Code generation for all textures



Edited by PantheR
MarinaNeiz likes this

Share this post

Link to post
Share on other sites

UIDesigner is getting better and better as i work with it on my own :) Just added draw order change for textures and fixed some bugs. Look at V1.6 changelog.

The idea of creating such component is exciting and interesting, hope someone will find it useful :)

Share this post

Link to post
Share on other sites

Trying to get the examples working but am getting 652 build errors that look like they are related to Xna

Error 1 The type or namespace name 'Xna' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
I have the latest mongame installed.

Share this post

Link to post
Share on other sites

Please check the project references for any inconsistencies that can appear on your system.


Project references assemblies from:

C:\Program Files (x86)\MSBuild\..\MonoGame\v3.0\Assemblies\WindowsGL\

These assemblies contains namespaces such as Microsoft.Xna.Framework


Also, as i know, the latest public release of Monogame is 3.0.1.

Share this post

Link to post
Share on other sites

I have installed the 3.1.2 alpha. To get monogame to work with VS2013.


Ok so I looked into it and it looks like 3.1.2 has some issues with "\MonoGame\v3.0\Assemblies\WindowsGL\" but I was able to get it working by removing the ref to that and adding a ref to "\MonoGame\v3.0\Assemblies\Windows\".

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now