Using Monogame

Here are links and instructions to create a Monogame project and do some basic things like adding resources.

Creating your First Monogame Project

Using VS 2019

Here are instructions for creating your first Monogame Project:

***I would recommend creating a Monogame Windows Desktop Application (DirectX) in the Create a New Project step instead of the suggested OpenGL as demonstrated in the tutorial below, especially on older computers.

https://docs.monogame.net/articles/getting_started/2_creating_a_new_project_vs.html

Remember to go to File->Add to Source Control to create a Git repo.

Using VS 2022

Since the Monogame Extension hasn't been added yet to VS2022, we will have to make our Monogame projects using the CLI (powershell at school). It is relatively ease.

Click Here for instructions.

Understanding the Code

Here is a good description of what the various parts of the template are for. It is important for you to read and understand this:

https://docs.monogame.net/articles/getting_started/3_understanding_the_code.html

Here are some important take aways:

  • The Initialize() method is where you should set your initial values for whatever variables you want to use.

      • The Initialize() method calls LoadContent() using this line of code: base.Initialize();

      • If there are values that you need to initialize, but don't have values for until you have loaded the content (such as the dimensions of a texture), you can initialize those values after base.Initialize(); has been run inside your Initialize() method.

  • The LoadContent() method is where you will load any textures, sound files etc. into your program.

  • Adding Content

  • In order to add any textures, sounds, etc. to your Monogame project, you will need to use the MGCB tool. This process will be referred to throughout various tutorials, so you will need to get used to using it. The tool will create the necessary entry in your projects Content.MGCB file with instructions on how to process whatever content you are loading.

  • Here is an explanation on how to do this:

https://docs.monogame.net/articles/getting_started/4_adding_content.html

  • These are the steps you will need to follow to use something like a texture (from an image file) in your project:

1 - Load the image file into your project using the MGCB tool.

  • Make sure you click 'Build' to update the Content.mgcb file.

2 - Create a variable to store the texture in your project.

  • Typically done in the global space of your Game.cs file.

3 - Initialize the variable by loading the content in the LoadContent() method.

4 - Draw the texture in the Draw() method.

You may apply logic in your Update() method that will affect how your texture will be drawn.

Adding Basic Code

Here is how yu can add some basic animation code:

https://docs.monogame.net/articles/getting_started/5_adding_basic_code.html

Good Basic Monogame Tutorials

I have some tutorials and example programs that I have made, but I am not going to repeat the basics that you can easily find. I will assume in any tutorial that I provide that you are able to add content, load it and draw it on your own.

RB Whitaker's Tutorials

This first set of tutorials does a good job of providing the basics. I would recommend starting with his 2D Tutorial and Input Tutorial.

http://rbwhitaker.wikidot.com/monogame-tutorials

Games From Scratch

These are a bit older, but there is some good stuff here that you may wish to look at.

https://gamefromscratch.com/monogame-tutorial-series/

Making a new Project using the CLI

Make Project with CLI Monogame.pdf