You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/tutorials/building_2d_games/02_getting_started/index.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -165,7 +165,7 @@ After selecting *Create Project*, a new C# project will be created based on the
165
165
166
166
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
167
167
168
-
||
168
+
||
169
169
| :---: |
170
170
|**Figure 2-2: The default MonoGame cornflower blue game window**|
Copy file name to clipboardExpand all lines: articles/tutorials/building_2d_games/03_the_game1_file/index.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ At the core of a MonoGame project is the [**Game**](xref:Microsoft.Xna.Framework
14
14
15
15
Locate the *Game1.cs* file that was generated when you created the MonoGame project and open it. The default content will be:
16
16
17
-
[!code-csharp[](./files/game1.cs)]
17
+
[!code-csharp[](./snippets/game1.cs)]
18
18
19
19
This class provides the following structure:
20
20
@@ -33,19 +33,19 @@ Figure 3-1 below shows the lifecycle of a MonoGame game including the [**Update*
33
33
34
34
The graphics pipeline in monogame starts with two components: the [**GraphicsDeviceManager**](xref:Microsoft.Xna.Framework.GraphicsDeviceManager) and [**SpriteBatch**](xref:Microsoft.Xna.Framework.Graphics.SpriteBatch).
The [**GraphicsDeviceManager**](xref:Microsoft.Xna.Framework.GraphicsDeviceManager) initializes and the connection to the graphics hardware. It handles tasks such as setting the screen resolution, toggling between fullscreen and windowed mode, and managing the [**GraphicsDevice**](xref:Microsoft.Xna.Framework.Graphics.GraphicsDevice), which is the interface between your game and the Graphics Processing Unit (GPU) the game is running on. The [**SpriteBatch**](xref:Microsoft.Xna.Framework.Graphics.SpriteBatch) optimizes 2D rendering by batching similar draw calls together, improving draw performance when rendering multiple sprites.
39
39
40
40
## Initialization
41
41
42
42
MonoGame's initialization process for your game follows a specific sequence. The constructor runs first, which handles basic setup like creating the [**GraphicsDeviceManager**](xref:Microsoft.Xna.Framework.GraphicsDeviceManager), setting the content directory, and the visibility of the mouse.
After that, the [**Initialize**](xref:Microsoft.Xna.Framework.Game.Initialize) method executes, providing a dedicated place for additional configuration and initializations.
This separation allows you to perform setup tasks in a logical order; core systems in the constructor and game-specific initializations in the [**Initialize**](xref:Microsoft.Xna.Framework.Game.Initialize) method. The call to `base.Initialize()` should never be removed, as this is where the graphics device is initialized for the target platform.
51
51
@@ -56,7 +56,7 @@ This separation allows you to perform setup tasks in a logical order; core syste
56
56
57
57
The [**LoadContent**](xref:Microsoft.Xna.Framework.Game.LoadContent) method serves as the place for asset management. Here you can load textures, sound effects, music, and other game assets. We will cover loading assets in the coming chapters as we discuss each asset type that can be loaded. In a new project, the only task it performs is initializing a new instance of the [**SpriteBatch**](xref:Microsoft.Xna.Framework.Graphics.SpriteBatch).
This method is only call once during the startup of the game, but *when* it is called can be a little confusing at first. In the [**Initialize**](xref:Microsoft.Xna.Framework.Game.Initialize) method shown above, when the `base.Initialize` call is executed, the final task it performs is calling the [**LoadContent**](xref:Microsoft.Xna.Framework.Game.LoadContent) method. This means any initializations you need to perform that have a dependency on assets being loaded should be done *after* the `base.Initialize` call and not *before* it.
62
62
@@ -66,7 +66,7 @@ MonoGame implements a *game loop* by calling [**Update**](xref:Microsoft.Xna.Fra
66
66
67
67
MonoGame is executing the [**Update**](xref:Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime)) method and then the [**Draw**](xref:Microsoft.Xna.Framework.Game.Draw(Microsoft.Xna.Framework.GameTime)) method 60 times per second.
The [**Update**](xref:Microsoft.Xna.Framework.Game.Update(Microsoft.Xna.Framework.GameTime)) method at the moment is not doing much, only checking for input from a controller or keyboard to determine if the game should exit. However, the [**Draw**](xref:Microsoft.Xna.Framework.Game.Draw(Microsoft.Xna.Framework.GameTime)) method is doing more than what it appears to at first glance.
For the same amount of steps, you also get the benefit of the assets being pre-processed and compiled to an optimized format for the target platform. For instance, image files can be compiled using [DXT compression](https://en.wikipedia.org/wiki/S3\_Texture\_Compression), which is a format that is understood by GPUs without needing to be decompressed first, reducing the memory footprint.
36
36
@@ -60,10 +60,9 @@ There are different methods of opening the MGCB Editor tool depending on your ID
60
60
61
61
To open the *Content.mgcb* content project file in the MGCB Editor with Visual Studio Code, you can use the *MonoGame for VSCode* extension. You should have installed this extension in [Chapter 02](../02_getting_started/index.md#installing-the-monogame-for-vscode-extension). With this extension install, anytime you have a code file open, you will see the MonoGame logo in the top-right of the code window like below:
62
62
63
-
64
-
||
63
+
||
In Figure 6-2 above, you can see the user interface for the MGCB Editor:
86
+
In Figure 5-3 above, you can see the user interface for the MGCB Editor:
88
87
89
88
-**Toolbar**: Contains icon buttons for common actions such as creating new items, opening files, saving changes, and building content.
90
89
-**Project Panel**: Located on the left of the MGCB Editor, displays a hierarchial tree view of all content items added to the content project. The root node *Content* represents the root of the content project.
@@ -106,9 +105,9 @@ When adding existing assets to the content project, a pop-up dialog will appear
106
105
-**Add a link**: Creates a reference to the original file without making a copy. This maintains a connection to the source file, so any updates to the original will be included when you build. Note that the link uses a path relative to the Content.mgcb file, so if either the source file or your project moves, you'll need to reestablish the link.
107
106
-**Skip**: Cancels adding the current file while continuing with any other selected files.
The new folder will appear in your content tree, and you can now add items to it by:
148
147
@@ -216,9 +215,9 @@ When the [**ContentManager**](xref:Microsoft.Xna.Framework.Content.ContentManage
216
215
217
216
Let's walk through the process of editing our content project using the MGCB Editor to add a new image asset and then load it in our game. To get started, we'll first need an image to load. Right-click the following image of the MonoGame logo and save it named *logo.png* somewhere on your computer:
Now that we have an image file to add, perform the following:
224
223
@@ -236,9 +235,9 @@ Now that we have an image file to add, perform the following:
236
235
> [!IMPORTANT]
237
236
> After changes have been made in the MGBC Editor, ensure that you save the changes. They are not automatically saved, though you will be warned if you close the editor and haven't saved changes. You can tell that changes have not been saved by looking at the title bar of the MGCB editor window. If it has an '*' at the end of the window title, this means changes have not been saved
238
237
239
-
||
238
+
||
|**Figure 6-8: The logo image added to the content project in the MGCB Editor**|
240
+
|**Figure 5-8: The logo image added to the content project in the MGCB Editor**|
242
241
243
242
With the MonoGame logo image now added to the content project, we can load it in our game and draw it. Open the *Game1.cs* file and make the following changes:
244
243
@@ -247,17 +246,17 @@ With the MonoGame logo image now added to the content project, we can load it in
247
246
The key changes made here are:
248
247
249
248
1. The private field `_logo` was added to store the logo [**Texture2D**](xref:Microsoft.Xna.Framework.Graphics.Texture2D) once it is loaded.
250
-
2. In [**LoadContent**](xref:xref:Microsoft.Xna.Framework.Game.LoadContent), the logo texture is loaded using the [**ContentManager**](xref:Microsoft.Xna.Framework.Content.ContentManager).
251
-
3. In [**Draw**](xref:xref:Microsoft.Xna.Framework.Game.Draw(Microsoft.Xna.Framework.GameTime)) the logo is drawn using the [**SpriteBatch**](xref:xref:Microsoft.Xna.Framework.Graphics.SpriteBatch).
249
+
2. In [**LoadContent**](xref:Microsoft.Xna.Framework.Game.LoadContent), the logo texture is loaded using the [**ContentManager**](xref:Microsoft.Xna.Framework.Content.ContentManager).
250
+
3. In [**Draw**](xref:Microsoft.Xna.Framework.Game.Draw(Microsoft.Xna.Framework.GameTime)) the logo is drawn using the [**SpriteBatch**](xref:Microsoft.Xna.Framework.Graphics.SpriteBatch).
252
251
253
252
> [!NOTE]
254
253
> We'll go more into detail about the [**SpriteBatch**](xref:Microsoft.Xna.Framework.Graphics.SpriteBatch) in the next chapter.
255
254
256
255
Running the game now will show the MonoGame logo displayed in the upper-left corner of the game window.
257
256
258
-
||
257
+
||
0 commit comments