Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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
Tweet

More Decks by Syntax Conference

Other Decks in Programming

Transcript

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

    Twitter: @chrisgwilliams Email: [email protected] Blog: blog.bigrobotgames.com
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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 https://github.com/mono/MonoGame/wiki/Tutorials:-Getting-Started-on-Linux Mac OS requires Mac Developer Program account https://developer.apple.com/programs/mac/ Playstation 4 requires acceptance in Sony Dev program (http://us.playstation.com/develop/) Playstation Mobile requires acceptance in Sony Dev program (http://us.playstation.com/develop/) Ouya https://devs.ouya.tv/developers/docs/mono-game Android http://gamasutra.com/blogs/MattHughson/20140428/216416/XNA_to_MonoGa meAndroid__Porting_Primer.php Windows Phone 8 http://developer.nokia.com/community/wiki/XNA_Games_On_Windows_Phone _8_with_Monogame iOS (iPhone / iPad) requires iOS Developer Program account (https://developer.apple.com/programs/ios/)
  7. 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 http://www.monogame.net/downloads/ 3. XNA Content Compiler – You'll need this to compile things like SpriteFonts, audio files and certain image formats. You can find this at https://xnacontentcompiler.codeplex.com/.
  8. What To Get? Developing for Mac 1. XCode developer toolset

    – This is how you develop for Mac, and iOS. https://developer.apple.com/downloads/index.action. 2. XamarinStudio – Grab the latest MacOSX release (currently 5.10.1) from http://www.monodevelop.com. (This installs Mono Framework too.) 3. Install the MonoMac plug in (from within XamarinStudio) 4. MonoGame – Finally, download and install this, found here: https://github.com/mono/MonoGame.
  9. 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.)
  10. 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.)
  11. 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.
  12. 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); } }
  13. 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); }
  14. // 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);