In the last tutorial, I showed you how to instantiate a project in MonoGame.
In today’s tutorial, I will show you how to create a file with a class and implement it in the basic project.
Create a file in the folder named MyGame001 and rename this file ProblemReport.cs.
Add this source code to this file.
1 2 3 4 5 6 7 8 9 10 11 12 13 | // use namespace similar to the rest of the project namespace MyGame001 { public class ProblemReport { public static void test() { // source code } } } |
This created class can be used in various C# files, but now as an example, I have added it in the Game1.cs file:
1 2 3 4 | public Game1() { ProblemReport p = new ProblemReport(); ProblemReport.test(); |
You can see how the C# files were created to run the application correctly:
1 | [mythcat@desk MyGame001]$ dotnet run Program.cs |
First on run is Program.cs then Game1.cs with the class ProblemReport from ProblemReport.cs.