An Introduction to MonoGame

An Introduction to MonoGame

A session by Chris G Williams at Syntax Code & Craft Convention 2016


Syntax Conference

May 06, 2016


  1. MonoGame Overview 2016 Chris G. Williams ∙ Big Robot Games

    Twitter: @chrisgwilliams Email: Blog:

  3. What Is It? “Free software used by game developers to

    make their Windows and Windows Phone games run on other systems.“ Currently supports iOS, Android, MacOS, Linux, all Windows platforms, OUYA, PS4, PSVita, and Xbox One. It implements the Microsoft XNA 4 Application programming interface.
  4. Projects!

  5. What Is It? MonoGame is open source, and fully supports

    2D and 3D graphics, audio, networking, and multiple inputs including touch, mouse, gamepad, and keyboard. This is accomplished by use of the Mono framework, which is a free and open source .NET Framework compatible project created and maintained by Xamarin.
  6. Why Is It? Prior to 2006, you were stuck with

    C/C++ and sometimes Assembly Language for “serious” game development. In 2006, Microsoft released the XNA game development framework, and it was glorious. C#, Managed Code, Xbox 360 support. Truly a thing of beauty. Then, alongside the release of Windows 8, Microsoft killed it.
  7. Why Is It? Fortunately, MonoGame was already under development. XNA

    was closed source, and limited to just Microsoft platforms, but MonoGame supported iOS, Android, Windows, Linux, etc… with new platforms being added all the time. MonoGame is currently in version 3.5.1 and is still being actively developed.
  8. Supported Platforms Platform Additional Information Windows XP, 7 & 8

    MonoGame comes with templates for these OS’s. You’re all set. Windows GL This project type is for people who prefer OpenGL over DirectX Linux Mac OS requires Mac Developer Program account Playstation 4 requires acceptance in Sony Dev program ( Playstation Mobile requires acceptance in Sony Dev program ( Ouya Android meAndroid__Porting_Primer.php Windows Phone 8 _8_with_Monogame iOS (iPhone / iPad) requires iOS Developer Program account (
  9. What To Get? Developing for Windows 1. Visual Studio 2015

    – Any SKU will do, including the Express edition. If you are running Windows 8, get "Express 2013 for Windows" and if you're running an earlier operating system, like Windows 7, get Express 2013 for Windows Desktop. 2. MonoGame – Grab the latest release (currently 3.5.1) from 3. XNA Content Compiler – You'll need this to compile things like SpriteFonts, audio files and certain image formats. You can find this at
  10. What To Get? Developing for Mac 1. XCode developer toolset

    – This is how you develop for Mac, and iOS. 2. XamarinStudio – Grab the latest MacOSX release (currently 5.10.1) from (This installs Mono Framework too.) 3. Install the MonoMac plug in (from within XamarinStudio) 4. MonoGame – Finally, download and install this, found here:
  11. How Do I Use It? MonoGame provides a game loop

    and a handful of key methods: Update() Use this to update game object data (position, rotation, collision detection, etc…) and process player input. Draw() Use this to update the screen, calling the draw() method of your game objects (which should, in turn, use the spriteBatch object.)

  13. Important Game Objects SpriteBatch Enables a group of sprites to

    be drawn using the same settings. ContentManager Loads managed objects from the binary files and manages the lifespan of the loaded objects. GameTime Gives us time elapsed since last update (ElapsedGameTime) and time since the start of the game (TotalGameTime.)
  14. In a 2D game, everything on screen is a sprite.

  15. Even background images… …although you might not see all of

    it at once.
  16. So where’s the Sprite class? There isn’t one. Use the

    Texture2D type to store your image… Ball.BallTexture = content.Load<Texture2D>("soccer_ball"); and write custom classes for your game objects.
  17. For example: class Ball { public Vector2 Position; public Vector2

    Scale = Vector2.One; public float Rotation; public static Texture2D BallTexture; public static Vector2 Origin = Vector2.Zero; public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(BallTexture, Position, null, Color.White, Rotation, Origin, Scale, SpriteEffects.None, 0); } }
  18. protected override void Update(GameTime gameTime) { CheckForInput(); //spin them ball1.Rotation

    += (float)(gameTime.ElapsedGameTime.TotalSeconds * 3); //move them if (ball1.Position.X < 500) ball1.Position.X += 1; base.Update(gameTime); }
  19. // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)

    this.Exit(); // check for button press and shrink/expand ball if (GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed) ball1.Scale = new Vector2(ball1.Scale.X - 1, ball1.Scale.Y - 1); if (GamePad.GetState(PlayerIndex.One).Buttons.X == ButtonState.Pressed) ball1.Scale = new Vector2(ball1.Scale.X + 1, ball1.Scale.Y + 1);
  20. Demo time…

  21. Questions?