Today I started a new series of tutorials for those who follow this website related to C# programming and the .NET library called MonoGame.
The official website comes with many tutorials and information and documentation.
MonoGame is a simple and powerful .NET library for creating games for desktop PCs, video game consoles, and mobile devices.
Based on Microsoft’s XNA Framework, it provides the following features:
- Game framework
- 2D and 3D rendering
- Sound effect and music playback
- Keyboard, mouse, touch, and controller inputs
- Content building and optimization
- Math library optimized for games
Let’s start with the install this .NET library and some Fedora packages:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | [root@desk mythcat]# dnf install gtk-sharp3.x86_64 gtk-sharp3.i686 ... Installed: gtk-sharp3-2.99.3-30.fc33.i686 gtk-sharp3-2.99.3-30.fc33.x86_64 mono-core-6.8.0-7.fc33.i686 Complete!</code></pre> <pre><code>[mythcat@desk ~]$ wget https://github.com/cra0zy/ monodevelop-run-installer/releases/download/6.2.0.1778-1/monodevelop-6.2.0.1778-1.run [mythcat@desk ~]$ chmod +x monodevelop-6.2.0.1778-1.run [mythcat@desk ~]$ sudo ./monodevelop-6.2.0.1778-1.run Verifying archive integrity... All good. Uncompressing MonoDevelop .run Previous version detected, uninstalling... Copying MonoDevelop binaries... Adding terminal commands... Adding application icon... Adding application launcher... [mythcat@desk ~]$ wget http://www.monogame.net/releases/v3.6/monogame-sdk.run [mythcat@desk ~]$ chmod +x monogame-sdk.run [mythcat@desk ~]$ sudo ./monogame-sdk.run Verifying archive integrity... All good. Uncompressing Monogame Pipeline ... Optional Dependencies: - MonoDevelop 6..................................[Found] - Rider..........................................[Not Found] - referenceassemblies-pcl / mono-pcl.............[Found] - ttf-mscorefonts-installer / mscore-fonts.......[Not Found] Continue (Y, n): y Previous version detected, trying to uninstall... Installing MonoGame SDK... Installing MonoDevelop Addin... Creating launcher items... gtk-update-icon-cache: Cache file created successfully. Adding mimetype... To uninstall MonoGame SDK you can run "monogame-uninstall" from terminal. [mythcat@desk ~]$ dotnet new --install MonoGame.Templates.CSharp [mythcat@desk ~]$ dotnet tool install --global dotnet-mgcb-editor ... [mythcat@desk ~]$ mgcb-editor --register ... Installation complete! Registered MGCB Editor! |
MonoGame Content Builder (MGCB) Editor is the front-end GUI editor for MonoGame content builder projects.
You can run it with this command:
1 | [mythcat@desk MyGame001]$ mgcb-editor |
Let’s create a simple project named MyGame001:
1 2 3 4 5 6 7 8 9 | [mythcat@desk ~]$ mkdir MonoGameProjects [mythcat@desk ~]$ cd MonoGameProjects [mythcat@desk MonoGameProjects]$ dotnet new mgdesktopgl -o MyGame001 The template "MonoGame Cross-Platform Desktop Application (OpenGL)" was created successfully. An update for template pack MonoGame.Templates.CSharp::3.8.0.1641 is available. install command: dotnet new -i MonoGame.Templates.CSharp::3.8.0.1641 [mythcat@desk MyGame001]$ ls app.manifest Content Game1.cs Icon.bmp Icon.ico MyGame001.csproj Program.cs |
You can see the Target Platforms with this command:
1 2 3 4 5 6 7 8 9 10 | [mythcat@desk MonoGameProjects]$ dotnet new -l | grep MonoGame MonoGame Android Application mgandroid [C#] MonoGame MonoGame Cross-Platform Desktop Application (OpenGL) mgdesktopgl [C#] MonoGame MonoGame iPhone/iPad Application mgios [C#] MonoGame MonoGame Windows Universal Application (CoreApp) mguwpcore [C#] MonoGame MonoGame Windows Universal Application (XAML) mguwpxaml [C#] MonoGame MonoGame Windows Desktop Application (Windows DirectX) mgwindowsdx [C#] MonoGame MonoGame NetStandard Library mgnetstandard [C#] MonoGame MonoGame Pipeline Extension mgpipeline [C#] MonoGame MonoGame Shared Library Project mgshared [C#] MonoGame |
The project comes with these files:
1 2 3 | [mythcat@desk MonoGameProjects]$ cd MyGame001/ [mythcat@desk MyGame001]$ ls app.manifest Content Game1.cs Icon.bmp Icon.ico MyGame001.csproj Program.cs |
The Programm.cs is the main project file and has this source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | using System; namespace MyGame001 { public static class Program { [STAThread] static void Main() { using (var game = new Game1()) game.Run(); } } } |
The last step for testing this source code is the running process:
1 | [mythcat@desk MyGame001]$ dotnet run Program.cs |
I tested and runs well.