MonoGame: build a 2D game in C# with the successor to XNA

ξ€£

October 5 2026

If you have ever touched XNA, you know the pattern: one game class, one method that updates the logic, one method that draws, all of it running in C#. MonoGame keeps that exact idea and carries it further than Microsoft did. The framework is open source, it runs on Windows, macOS and Linux, and it can export to mobile and consoles. It is an honest starting point for building a 2D game without a full engine.

What MonoGame actually is

MonoGame is not an engine with an editor, a scene view and an inspector. It is a library: it handles the window, rendering, sound, and keyboard, gamepad and mouse input, then leaves the rest to you. There is no drag and drop. You decide how your code is structured, how a level is loaded, how collisions work. That means more work at the start than with Unity or Godot, and it is also what makes learning with it so useful.

The project began as a reimplementation of XNA 4, which is why old XNA tutorials still work almost unchanged. If you want to see where that philosophy comes from, our XNA 4.0 Hello World guide (in French) lays out the basics.

Installing MonoGame and creating a first project

You need the .NET SDK installed, then two commands in a terminal. The first installs the project templates, the second creates a cross-platform desktop game based on OpenGL.

dotnet new install MonoGame.Templates.CSharp
dotnet new mgdesktopgl -n MyFirstGame
cd MyFirstGame
dotnet run

A blue window opens. That is the default background color, and it proves everything works. The same project opens without changes in Visual Studio, Visual Studio Code or Rider.

How a MonoGame project is organized

In the new folder, the first file to open is Game1.cs. It contains four methods that form the backbone of every MonoGame game. Initialize prepares variables, LoadContent loads images and sounds, Update moves the logic forward on every frame, and Draw displays the result. The framework calls Update then Draw about sixty times per second, and filling those two methods is your job.

Here is a short example that displays a sprite and moves it with the arrow keys.

private Texture2D _player;
private Vector2 _position = new Vector2(100, 100);

protected override void LoadContent()
{
    _spriteBatch = new SpriteBatch(GraphicsDevice);
    _player = Content.Load<Texture2D>("player");
}

protected override void Update(GameTime gameTime)
{
    var keyboard = Keyboard.GetState();
    float speed = 200f * (float)gameTime.ElapsedGameTime.TotalSeconds;

    if (keyboard.IsKeyDown(Keys.Right)) _position.X += speed;
    if (keyboard.IsKeyDown(Keys.Left))  _position.X -= speed;
    if (keyboard.IsKeyDown(Keys.Down))  _position.Y += speed;
    if (keyboard.IsKeyDown(Keys.Up))    _position.Y -= speed;

    base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);
    _spriteBatch.Begin();
    _spriteBatch.Draw(_player, _position, Color.White);
    _spriteBatch.End();
    base.Draw(gameTime);
}

The detail that matters here is the multiplication by ElapsedGameTime. It makes movement independent of the computer's speed. Without it, the character would move twice as fast on a machine that renders twice as many frames.

The Content Pipeline for images and sounds

Assets go through a tool called the Content Pipeline. You open Content.mgcb in the MGCB editor, add your player.png image, and it is converted to an optimized format that Content.Load can read. The name used in code is the file name without its extension. If loading fails at launch, the cause is almost always a file missing from that list.

Which projects suit MonoGame

The framework works well for 2D games, quick prototypes, platformers, top-down role-playing games, and any project where you want control over every line of code. Several well-known indie games are built on it. If you need a visual editor, a ready-made particle system or advanced 3D, a full engine will save you time. Our Unreal Engine vs Unity vs Godot comparison and the article on Godot 4 or Unity for a first game help you decide based on your project.

Where to go next

A good second exercise is to add an enemy, detect the collision between two rectangles with Rectangle.Intersects, and display a score with a SpriteFont. Once those three pieces are in place, you have the mechanics of a small complete game. The rest is code organization and game design ideas.

Recent Posts

Recent Comments

"

Itamde is also an online programming school.

Itamde

Learn what you want, at your own pace

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You may also be interested in...

Javascript

Introduction to jQuery and how it simplifies JavaScript

When you start writing JavaScript, one of the first things you feel is that you are surrounded by lines, by functions and sometimes by far too many semicolons. You find yourself writing and rewriting similar things, like reaching for an HTML element or responding to a...

Stay up to date with the latest news and developments

Access restricted content

Discover behind-the-scenes details of our projects, exclusive resources, and the progress of our creations in real time.

Sign up for our newsletter

Receive our news, creative insights, and updates from the studio directly in your inbox.

Follow us

Join our community on social media to follow our daily projects and interact with us.