Ihave same issue, I managed to solve the problem by manually modifying the project file in one computer and checked in to source control. but when I try to open the same project in another computer, I get this error:
Could not execute because the specified command or file was not found.
Possible reasons for this include:
So when you create a new MonoGame 3.8.1 project, it should do a NuGet restore automatically to ensure the tooling is setup, but you can always manually NuGet restore in Visual Studio or run the dotnet restore command from the project directory.
This was awesome, thanks so much for that in depth fix. My team and I have been struggling with this, I was having my artists and audio folks editing the content xml file directly, which was not popular for them lol.
However, if you are migrating from 3.8.0, you will need to setup a configuration file. Next to your .csproj, create a folder nammed .config and a file within it nammed dotnet-tools.json with this content:
Please note that you can't use the 3.8.1.* wildcard in the dotnet-tools.json file (tool versions have to be fully qualified). We strongly recommand that the versions match the MonoGame version referenced in your .csproj (if you're using the * wildcard, make sure that they don't end up mismatching if the nugets are updated without you noticing).
I am having a major issue moving my project to my M1 Mac so I can do a iOS version. The latest issue is I get an error in the editor An Error occurred trying to start process botnet with work directory Path to content No such file or directory.
I have read the documentation page for packaging and it seems like it only contains instructions for compiling for osx-x64. However I would like to compile for osx-arm64.
So I ran this command: dotnet publish -c Release -r osx-arm64 /p:PublishReadyToRun=false /p:TieredCompilation=false --self-contained on my windows machine, built an application bundle according to the folder structures and sent it to my friend who owns a M1 Mac. When he ran it his system showed this:
MonoGame is an open-source, cross-platform game development framework capable of building 2D and 3D games. It is built from the now-expired Microsoft XNA framework, which was popular back in the Xbox 360 days for creating games on the Xbox and PC.
As a game developer, using MonoGame might seem backward in the world of advanced game engines like Unity and Unreal Engine, which provide many tools and components for you that we'd otherwise have to program ourselves. However, building components of the engine that are specific to your game requires you to understand the code at a far deeper level, which will make you better at identifying programming patterns.
In this tutorial, you will learn how to create a Pong game using MonoGame and C#. This tutorial covers setting up the environment, creating the Paddle and Ball classes, handling collisions, and displaying the score. A basic knowledge of object-oriented programming languages such as C# or C++ is assumed. By the end of this tutorial, you will have a fully functional Pong game to play with a friend and a deeper understanding of MonoGame's framework.
The recommended way to install MonoGame is by using Visual Studio 2022, because there is already an extension you can use directly in the IDE. Creating a project is a lot more simplified in this way. Follow this guide by MonoGame to install it for your specific operating system. You will also be able to run it in the command line without an IDE, if you prefer Visual Studio Code, vim, or some other code editor.
Now that you've created a MonoGame project, you'll see that a lot of files have been generated where you created the project. If you're using Visual Studio 2022, go ahead and run the program with the debug button or by pressing F5. If you're using the command line, type dotnet run. When you run the project, a blue window should pop up.
The project that is automatically generated has a lot of files in it, so it may be overwhelming to look at first glance. But, we'll go through the important ones right now and try to understand how the code is structured. This is the general file structure:
While there are ways we can reorganize that make sense for a project you'd be working on long term, right now we can use the default structure since we're just making Pong. That being said, the only file we will concern ourselves with (right now) is Game1.cs which is our game runs.
We're going to try and avoid running too much game logic in the Game1 class, as we want to have clear roles for all the objects in the game. For this project, we can simplify the classes we will make as just Paddle and Ball. It may be more intelligent to organize more so there is more separation and more flexibility to change things about the game in the future, but for this tutorial, we're going to just worry about getting a working Pong.
In our Globals class, we want to store some public global variables, so that we can access them from anywhere in our game. For now, we're going to store the width and height of our screen, as well as SpriteBatch, which is going to make drawing things to the screen possible.
Because we've created a global variable spriteBatch, we can replace all instances of the local private one with the global version. Go into your Game1 class, and delete the _spriteBatch class variable that was automatically created.
To draw game objects on the screen, start the drawing process by using the Begin() method on the Globals.spriteBatch object. This sets up everything needed to show our game elements. After finishing all drawing tasks, end the process by using the End() method on the Globals.spriteBatch object. This makes sure all drawing operations are done and the elements show up on the screen.
In computer graphics, we use a different coordinate system than the usual one from math class. The top-left corner of the screen is the starting point (0,0). The x-axis shows the horizontal position, and the y-axis shows the vertical position. This system makes it easier to work with graphics on screens and in programming.
Here, we are accessing the global spriteBatch variable, and drawing our rectangle to it with our essentially empty texture, with the color white. Because our pixel variable is white, we can set our Color to any color we want, but in this case, we'll just keep it white to stay true to the original Pong.
rect.Y -= (int)(moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds); is changing the Y position of the paddle, so that it can go up based on the moveSpeed multiplied by the time between the last frame and the current frame. We call this delta time (the difference between the previous and current frame).
if (kstate.IsKeyDown(Keys.S) && rect.Y If you've done everything correctly, we should have movement! All we have to do now is add a second player, which should be super easy now that we've made our Paddle class! We just need to allow the constructor to take in a parameter, if it's the second player or not, and then make modifications accordingly.
Also, we are going to take in both Paddle instances, since we want to use the Ball for all game calculations. This isn't necessarily the best practice, but since it's a simple game like Pong, it's alright.
We will use right and top to store either 1 or -1 so that we can create conditionals for when the ball collides with something. We're going to want to keep it simple, so the ball will always move at a 45 angle. By adding the same values to the X and the Y of the ball, it will always bounce at the same 45 angle.
We're calling a function resetGame() that we haven't made yet! We want this to put the ball back at the center of the game, which should be easy for us. Go ahead and create it as part of the Ball class.
In MonoGame, displaying text on the screen requires loading a font resource, typically in the form of a SpriteFont. This allows you to present information such as scores, game instructions, and other textual elements in your MonoGame project.
The Score.spritefont file we created is just a standard XML file, that defines properties of the font. By default, the font selected is Arial, which is fine, but you can go in there and make it any font you want, just make sure that you add the .ttf file to the Content folder if you don't already have it installed on your machine.
For me, I downloaded the Press Start Font , and put the file in the Content folder, then opened the Score.sprintefont file and changed it from Arial to the name of the .ttf file, in my case prstart. I chose this font because it has a nice 8-bit style.
Great job on completing the Pong game tutorial using MonoGame and C#! This achievement has not only helped you build a classic game but also allowed you to gain hands-on experience in game development concepts. As you continue exploring new projects and honing your skills, you will become more proficient in game development.
Let's start with the Android. I won't go into detail on the parts that did work fine, so you can follow the Getting Started docs for this part. If you're using the .NET Core template its name is mgandroid. Call it something like "Game.Android". This will be a C# project because that's the only available Android template and it doesn't matter because we won't be writing our game code here. You should now have a project which runs the cornflower blue screen on your phone or emulator.
Now we want to do the same for a desktop GL project so we can develop without having to deploy to the phone every time. There is an F# template for this, but it is not on NuGet as far as I can see at the time of writing. No problem, we can just go to the repo and get it. Either clone it or download the zip. Chuck that alongside our Android project and rename it something like "Game.Desktop". You could also install it as a dotnet template with dotnet new -i . Ok, you should be able to run this straight away and see the cornflower blue as well.
3a8082e126