How to run your MonoGame game in a WinForms control?

How to run your MonoGame game in a WinForms control?

This post is a follow-on to my previous entry: Bringing your XNA WinForms Controls to MonoGame + OpenGL. In my previous entry, one reader brought up a good question: once you have your MonoGame-based WinForms control working, how do you run your game in it?

Can you use MonoGame’s game.cs as a reference?

You can use MonoGame’s Game.cs implementation as a reference for replacing services. Or you could just steal huge swathes of it outright. Here’s a basic implementation of a game as if it were a normal MonoGame project. Instead of extending from Game, we’re extending from GameControl. This is where your game’s architecture becomes interesting.

How does WinForms series project with embedded game work?

The WinForms series project with an embedded game. The Game object that you typically derive your project from is designed to create and manage its own native window and rendering environment, with all the guts hidden away so its usage appears to be platform-independent.

Do you need to wrap game object in MonoGame?

Doing so would allow you to directly wrap your derived Game object. If you want to stick to stock MonoGame code, then it needs to be replaced. Hopefully you’ve architected your game to not depend on an explicit instance of the Game object being available everywhere.

How to add render control to MonoGame forms?

Adding one render control to your forms project is fairly easy: You just inherit from the DrawWindow or UpdateWindow class and override the corresponding Initialize () [Update ()] and Draw () methods. A draw window is updated through invalidation. An update window is updated by a real game loop.

How are MonoGame views used in a Xamarin forms cross platform application?

For some context, here is how the MonoGame views are used in a Xamarin Forms cross platform application. Very little code is needed to get MonoGame running in a control anywhere within an Xamarin Forms application. A custom renderer is needed for each platform so the Xamarin Forms code ( netstandard2.0) is very simple.