Skip to content

Commit aea2cc3

Browse files
Merge branch '2d-tutorial-bounty' into 20-the-game
2 parents 1269cde + e28e203 commit aea2cc3

File tree

60 files changed

+570
-2626
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+570
-2626
lines changed
Loading

articles/tutorials/building_2d_games/01_what_is_monogame/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ The official first release of MonoGame occurred in 2011, as an open-source versi
1717

1818
Today, MonoGame is a mature cross-platform framework, that is built with the spirit of preserving XNA while adopting modern game development practices. Some popular titles created using MonoGame includes [Celeste](https://store.steampowered.com/app/504230/Celeste/), [Stardew Valley](https://store.steampowered.com/app/413150/Stardew\_Valley/), and [Streets of Rage 4](https://store.steampowered.com/app/985890/Streets\_of\_Rage\_4/).
1919

20-
| ![Figure 1-1: Celeste](./images/celeste.png) | ![Figure 1-2: Stardew Valley](./images/stardew-valley.png) |
21-
| :---: | :---: |
22-
| **Figure 1-1 Celeste.** | **Figure 1-2: Stardew Valley** |
23-
| ![Figure 1-3: Streets of Rage 4](./images/sor4.jpg) | |
24-
| **Figure 1-3: Streets of Rage 4** | |
20+
| ![Figure 1-1: Celeste](./images/celeste.png) | ![Figure 1-2: Stardew Valley](./images/stardew-valley.png) |
21+
| :-------------------------------------------------: | :--------------------------------------------------------: |
22+
| **Figure 1-1 Celeste.** | **Figure 1-2: Stardew Valley** |
23+
| ![Figure 1-3: Streets of Rage 4](./images/sor4.jpg) | [Figure 1-4: Bastion](./images/bastion.jpg) |
24+
| **Figure 1-3: Streets of Rage 4** | **Figure 1-4: Bastion** |
2525

2626
## Features
2727

Loading

articles/tutorials/building_2d_games/02_getting_started/index.md

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,35 @@ Unlike game engines, MonoGame is a *framework*. This means it does not come as a
88
* **Flexibility**: Developers are not locked into using a specific editor or interface, allowing them to use their preferred development tools.
99
* **Integration**: As a .NET library itself, MonoGame can easily integrate with other .NET libraries and tools.
1010
* **Cross-platform Development**: Since C# is cross-platform, and MonoGame is cross-platform, developers can develop MonoGame projects on Windows, macOS, or Linux, with only slight differences in the setup process for each operating system.
11-
* **Version Control Friendly**: The code-first approach makes it easier to use version control systems like Git for you game projects.
11+
* **Version Control Friendly**: The code-first approach makes it easier to use version control systems like Git for your game projects.
1212

1313
While the environment setup process is similar to the standard setup process for C# development, there are some MonoGame specific steps. These can vary slightly depending on your operating system and the *Integrated Development Environment* (IDE).
1414

1515
## Installing the .NET SDK
1616

17-
The first thing we need to do is install the .NET *Software Development Kit* (SDK). At the time of this writing, MonoGame targets the .NET 8.0 SDK.
17+
The first thing we need to do is install the .NET *Software Development Kit* (SDK). To install it, follow the instructions based on your operating system below:
1818

19-
> [!NOTE]
20-
> At the time of writing this tutorial, .NET 9.0 is released, however this tutorial still recommends installing .NET 8.0 for two reasons
21-
>
22-
> 1. .NET 8.0 is the current Long-Term Support (LTS) release of .NET. This means it receives security updates and bug fixes for 3 years, while Standard-Term Support (STS) releases like .NET 9.0 provide a shorter support window, typically around 18 months. For more information see the [.NET and .NET Core official support policy](https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core#cadence) page.
23-
> 2. MonoGame targets the LTS version of .NET, meaning it targets .NET 8.0, so we are using the same version for consistency.
24-
25-
To install it, follow the instructions based on your operating system below
19+
> [!IMPORTANT]
20+
> As of MonoGame 3.8.2, the minimum supported version of the .NET SDK is .NET 8.
2621
2722
### [Windows](#tab/windows)
2823

2924
1. Open a web browser and navigate to https://dotnet.microsoft.com/en-us/download.
30-
2. Click the *Download .NET SDK x64* button to start the download of the .NET SDK Installer.
25+
2. Choose the version of the .NET SDK to install and click the **Download .NET SDK x64** button to start the download.
26+
27+
> [!NOTE]
28+
> The minimum supported version is .NET 8
29+
3130
3. Once the download finishes, run the installer
3231

3332
### [macOS](#tab/macos)
3433

3534
1. Open a web browser and navigate to https://dotnet.microsoft.com/en-us/download.
36-
2. Click the *Download .NET SDK x64 (Intel)* button start the download of the .NET SDK Installer
35+
2. Choose the version of the .NET SDK to install and click lick the *Download .NET SDK x64 (Intel)* button start the download of the .NET SDK Installer.
36+
37+
> [!NOTE]
38+
> The minimum supported version is .NET 8
39+
3740
3. Once the download finishes, run the installer.
3841

3942
> [!NOTE]
@@ -48,6 +51,9 @@ To install it, follow the instructions based on your operating system below
4851
sudo apt-get update && sudo apt-get install -y dotnet-sdk-8.0
4952
```
5053

54+
> [!NOTE]
55+
> The minimum supported version is .NET 8
56+
5157
---
5258

5359
## Install Additional Workloads (Optional)
@@ -61,7 +67,7 @@ dotnet workload install android
6167

6268
## Install MonoGame Project Templates
6369

64-
MonoGame provides project templates that can be installed to create new projects that are pre-configured to target the current version of MonoGame as a base to begin creating games. As of this writing, the current version of MonoGame targeted is 3.8.3. To install the MonoGame templates, open a *Command Prompt* or *Terminal* window and enter the following command
70+
MonoGame provides project templates that can be installed to create new projects that are pre-configured to target the current version of MonoGame as a base to begin creating games. To install the MonoGame templates, open a *Command Prompt* or *Terminal* window and enter the following command
6571

6672
```sh
6773
dotnet new install MonoGame.Templates.CSharp
@@ -84,7 +90,7 @@ To install VSCode, follow the instructions for your operating system below:
8490
1. Open a web browser and navigate to https://code.visualstudio.com/.
8591
2. Click the *Download for macOS* button to start the download of the *.zip* archive.
8692
3. Once the download finishes, double click the *.zip* archive to extract the *Visual Studio Code.app* application package
87-
4. Drag-and-drop the *Visual Studio Code.app* application package into your *Application* directory to make it available in the macOS *LaunchPad*.
93+
4. Drag-and-drop the *Visual Studio Code.app* application package into your *Application* folder to make it available in the macOS *LaunchPad*.
8894

8995
### [Linux](#tab/linux)
9096

@@ -117,6 +123,10 @@ To install the C# Dev Kit extension, perform the following:
117123
3. Enter `C#` in the *Search Box*
118124
4. Click install for the *C# Dev Kit* extension.
119125

126+
| ![Figure 2-1: The C# Dev Kit Extension listed in Visual Studio Code](./images/devkit-extension.png) |
127+
| :-------------------------------------------------------------------------------------------------: |
128+
| **Figure 2-1: The C# Dev Kit Extension listed in Visual Studio Code** |
129+
120130
> [!NOTE]
121131
> When you search `C#` in the *Extension Panel* you may notice there is the C# Dev Kit extension and a base standard C# extension. When installing the C# Dev Kit extension, the base extension will also be installed as a requirement.
122132
@@ -150,7 +160,7 @@ wget -qO- https://monogame.net/downloads/net8_mgfxc_wine_setup.sh | bash
150160
```
151161

152162
> [!NOTE]
153-
> After performing these steps, a new directory called *.winemonogame* will be created in your home directory. If you ever wish to undo the setup performed by this script, you can simply delete this directory.
163+
> After performing these steps, a new folder called *.winemonogame* will be created in your home folder. If you ever wish to undo the setup performed by this script, you can simply delete this folder.
154164
155165
### [Linux](#tab/linux)
156166

@@ -162,7 +172,7 @@ wget -qO- https://monogame.net/downloads/net8_mgfxc_wine_setup.sh | bash
162172
```
163173

164174
> [!NOTE]
165-
> After performing these steps, a new directory called *.winemonogame* will be created in your home directory. If you ever wish to undo the setup performed by this script, you can simply delete this directory.
175+
> After performing these steps, a new folder called *.winemonogame* will be created in your home folder. If you ever wish to undo the setup performed by this script, you can simply delete this folder.
166176
167177
---
168178

@@ -180,17 +190,17 @@ With your development environment setup, it is time to create your first MonoGam
180190

181191
After selecting *Create Project*, a new C# project will be generated based on the chosen MonoGame template and opened automatically in VSCode.
182192

183-
| ![Figure 2-1: A new MonoGame project after being created in Visual Studio Code](./images/vscode.png) |
184-
| :---: |
185-
| **Figure 2-1: A new MonoGame project after being created in Visual Studio Code** |
193+
| ![Figure 2-2: A new MonoGame project after being created in Visual Studio Code](./images/vscode.png) |
194+
| :--------------------------------------------------------------------------------------------------: |
195+
| **Figure 2-2: A new MonoGame project after being created in Visual Studio Code** |
186196

187197
Now that we have the project created, press the `F5` key on your keyboard, or choose *Run > Start Debugging* from the top menu. If prompted for a configuration, choose *C#*. The project will compile and run, displaying a screen similar to the following:
188198

189-
| ![Figure 2-2: The default MonoGame cornflower blue game window](./images/game-window.png) |
190-
| :---: |
191-
| **Figure 2-2: The default MonoGame cornflower blue game window** |
199+
| ![Figure 2-3: The default MonoGame cornflower blue game window](./images/game-window.png) |
200+
| :---------------------------------------------------------------------------------------: |
201+
| **Figure 2-3: The default MonoGame cornflower blue game window** |
192202

193-
Be amazed, the default MonoGame Cornflower Blue game window. You have just created your very first MonoGame application. While there isn't much happening here visually, there is a log going on behind the scenes that the MonoGame framework is handling for you. When you ran the application, the following occurred:
203+
Be amazed, the default MonoGame Cornflower Blue game window. You have just created your very first MonoGame application. While there is not much happening here visually, there is a log going on behind the scenes that the MonoGame framework is handling for you. When you ran the application, the following occurred:
194204

195205
1. The application started
196206
2. The game window was created and graphics were initialized
@@ -209,7 +219,7 @@ You can exit the game at any time by pressing the `Esc` key on your keyboard.
209219
210220
## Conclusion
211221

212-
Let's review what you accomplished in this chapter:
222+
In this chapter, you accomplished the following:
213223

214224
* You setup your operating system to develop .NET applications by installing the .NET SDK
215225
* You installed the MonoGame project templates.
@@ -220,16 +230,22 @@ Now that your development environment is setup and ready to go, you can dive in
220230

221231
## Test Your Knowledge
222232

223-
1. What version of the .NET SDK is currently targeted by MonoGame applications?
233+
1. What are two advantages of MonoGame being a framework rather than an engine?
224234

225235
:::question-answer
226-
.NET 8.0
236+
Any two of the following:
237+
238+
- Flexibility: Developers can use their preferred development tools
239+
- Integration: MonoGame easily integrates with other .NET libraries
240+
- Cross-platform Development: Projects can be developed on Windows, macOS, or Linux
241+
- Version Control Friendly: The code-first approach works well with systems like Git
242+
227243
:::
228244

229-
2. What is the current version of MonoGame?
245+
2. What is the primary reason that game applications implement a *game loop* structure instead of using an event-based approach like traditional desktop applications?
230246

231247
:::question-answer
232-
3.8.3
248+
Game application implement a *game loop* structure because games need to continuously update and render, event when there is no user input. In games, objects might be moving, animations playing, and physics calculating regardless of user interaction, requiring constant updating and rendering until the game is told to exit.
233249
:::
234250

235251
3. What is the color of the game window when you run a MonoGame project for the first time?
Loading

articles/tutorials/building_2d_games/03_the_game1_file/index.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ After you created a new MonoGame project using the *MonoGame Cross-Platform Desk
99

1010
At the core of a MonoGame project is the [**Game**](xref:Microsoft.Xna.Framework.Game) class. This class handles the initialization of graphics services, initialization of the game, loading content, updating, and rendering the game. When you create a new Monogame project, this [**Game**](xref:Microsoft.Xna.Framework.Game) class is implemented as the `Game1` class that you can customize as needed for your specific game.
1111

12-
> [!TIP]
13-
> While the default template names the class `Game1`, you're free to rename it to something more appropriate for your project. However, for consistency, the documentation will continue to refer to it as `Game1`.
12+
> [!TIP]
13+
> While the default template names the class `Game1`, you are free to rename it to something more appropriate for your project. However, for consistency, the documentation will continue to refer to it as `Game1`.
1414
1515
Locate the *Game1.cs* file that was generated when you created the MonoGame project and open it. The default content will be:
1616

@@ -26,8 +26,8 @@ This class provides the following structure:
2626
Figure 3-1 below shows the lifecycle of a MonoGame game including the [**Update**](xref:Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime)) and [**Draw**](xref:Microsoft.Xna.Framework.Game.Draw(Microsoft.Xna.Framework.GameTime)) methods that make up the *game loop*.
2727

2828
| ![Figure 3-1: Lifecycle of a MonoGame game](./images/monogame-lifecycle.png) |
29-
| :---: |
30-
| **Figure 3-1: Lifecycle of a MonoGame game** |
29+
| :--------------------------------------------------------------------------: |
30+
| **Figure 3-1: Lifecycle of a MonoGame game** |
3131

3232
## Graphics and Rendering
3333

@@ -43,7 +43,7 @@ MonoGame's initialization process for your game follows a specific sequence. Th
4343

4444
[!code-csharp[](./snippets/game1.cs?start=12&end=17)]
4545

46-
After that, the [**Initialize**](xref:Microsoft.Xna.Framework.Game.Initialize) method executes, providing a dedicated place for additional configuration and initializations.
46+
After that, the [**Initialize**](xref:Microsoft.Xna.Framework.Game.Initialize) method executes, providing a dedicated place for additional configuration and initializations.
4747

4848
[!code-csharp[](./snippets/game1.cs?start=19&end=22)]
4949

@@ -73,18 +73,29 @@ The [**Update**](xref:Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framewor
7373
The first line is executing the [**Clear**](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice.Clear(Microsoft.Xna.Framework.Color)) method of the [**GraphicsDevice**](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice) property using the color [**CornflowerBlue**](xref:Microsoft.Xna.Framework.Color.CornflowerBlue). Recall that the [**GraphicsDevice**](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice) object is your direct interface between the game and what is rendered to the screen. Every time the [**Draw**](xref:Microsoft.Xna.Framework.Game.Draw(Microsoft.Xna.Framework.GameTime)) method is called, this line of code of erasing the contents of the game window and refilling it with the color specified. Without clearing the contents of the screen first, every draw call would draw the new frame render over top of the previous render, and you'd end up with something like the old solitaire win screen
7474

7575
| ![Figure 3-2: Windows XP Solitaire Win Screen](./images/solitaire.webp) |
76-
| :---: |
77-
| **Figure 3-2: Windows XP Solitaire Win Screen** |
78-
79-
While this can make for a neat effect, it is not something you want all the time. So, the screen is cleared and refilled with a solid color. You can test this yourself by modifying the code to use a different color, such as [**Color.MonoGameOrange**](xref:Microsoft.Xna.Framework.Color.MonoGameOrange), then running the game. (yes, there is a MonoGame Orange color).
76+
| :---------------------------------------------------------------------: |
77+
| **Figure 3-2: Windows XP Solitaire Win Screen** |
78+
79+
While this can make for a neat effect, it is not something you want all the time. So, the screen is cleared and refilled with a solid color.
80+
81+
> [!NOTE]
82+
> You can test this yourself by modifying the code to use a different color, such as [**Color.MonoGameOrange**](xref:Microsoft.Xna.Framework.Color.MonoGameOrange). (yes, there is a MonoGame Orange color).
83+
>
84+
> [!code-csharp[](./snippets/draw.cs?highlight=3)]
85+
>
86+
> After making this change and running the game, the screen is cleared to the MonoGame Orange color.
87+
>
88+
> | ![Figure 3-3: The game window clearing the screen using the MonoGame Orange color](./images/monogame-orange.png) |
89+
> | :---: |
90+
> | **Figure 3-3: The game window clearing the screen using the MonoGame Orange color** |
8091
8192
Each time the game loops completes and the game is drawn to the screen, we call this a *frame*. So if MonoGame is running the game loop at 60 frames per second, that means it is performing and update and a render of each frame in 16ms. Notice that both the [**Update**](xref:Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime)) and the [**Draw**](xref:Microsoft.Xna.Framework.Game.Draw(Microsoft.Xna.Framework.GameTime)) methods both receive a parameter of the type [**GameTime**](xref:Microsoft.Xna.Framework.GameTime). The [**GameTime**](xref:Microsoft.Xna.Framework.GameTime) parameter provides a snapshot of the timing values for the game, including the amount of time that it took for the previous frame to execute. This is commonly referred to as the *delta time*.
8293

8394
*Delta time* allows you to track time accurately for things such as animations and events based on *game time* and not the speed of the processor (CPU) on the machine running the game. While in ideal circumstances, the delta time will always be 16ms, there are any number of things that could cause a temporary slow down or hiccup in a frame, and using the delta time ensures that timing based events are always correct.
8495

8596
## Conclusion
8697

87-
Here is a review of what was accomplished in this chapter:
98+
In this chapter, you accomplished the following:
8899

89100
- You read through the default code provided in a *Game1.cs* file created by a MonoGame template.
90101
- You learned about the lifecycle of a MonoGame game project.
@@ -97,7 +108,7 @@ In the next chapter, you will start working with sprites and learn how to load a
97108
1. Can the `Game1` class be renamed or is it required to be called `Game1`
98109

99110
:::question-answer
100-
It is not a requirement that it be called `Game1`. This is just the default name given to it by the templates when creating a new MonoGame game project.
111+
It is not a requirement that it be called `Game1`. This is just the default name given to it by the templates when creating a new MonoGame game project.
101112
:::
102113

103114
2. What is the [**SpriteBatch**](xref:Microsoft.Xna.Framework.Graphics.SpriteBatch) used for?
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
protected override void Draw(GameTime gameTime)
2+
{
3+
GraphicsDevice.Clear(Color.MonoGameOrange);
4+
5+
base.Draw(gameTime);
6+
}

0 commit comments

Comments
 (0)