Skip to content

Commit 5c16c21

Browse files
Merge pull request #54 from AristurtleDev/feedback/chapter-20
Address Chapter 20 Feedback
2 parents ef99857 + c194c5a commit 5c16c21

File tree

1 file changed

+34
-15
lines changed
  • articles/tutorials/building_2d_games/20_implementing_ui_with_gum

1 file changed

+34
-15
lines changed

articles/tutorials/building_2d_games/20_implementing_ui_with_gum/index.md

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ To add the Gum NuGet package in Visual Studio Code:
319319
2. Choose `Add NuGet Package` from the context menu.
320320
3. Enter `Gum.MonoGame` in the `Add NuGet Package` search prompt and press Enter.
321321
4. When the search finishes, select the `Gum.MonoGame` package in the results
322-
5. When prompted for a version, choose the latest version ("2025.4.23.1" at the time of writing").
322+
5. When prompted for a version choose version `2025.5.1.1`.
323323

324324
#### [Visual Studio 2022](#tab/vs2022)
325325

@@ -330,7 +330,7 @@ To Add the Gum NuGet package in Visual Studio 2022:
330330
3. In the NuGet Package Manager window, select the `Browse` tab if it is not already selected.
331331
4. In the search box, enter `Gum.MonoGame`.
332332
5. Select the "Gum.MonoGame" package from the search results.
333-
6. Ensure the latest version is selected in the dropdown menu ("2025.4.23.1" at the time of writing") and click the *Install* button.
333+
6. On the right, in the version dropdown, select version `2025.5.1.1` and click the "Install" button.
334334

335335
#### [dotnet CLI](#tab/dotnetcli)
336336

@@ -340,20 +340,21 @@ To add the Gum NuGet package using the dotnet CLI:
340340
2. Enter the following command:
341341

342342
```sh
343-
dotnet add DungeonSlime.csproj package Gum.MonoGame
343+
dotnet add DungeonSlime.csproj package Gum.MonoGame --version 2025.5.1.1
344344
```
345345

346-
This will install the latest version of the package, which is "2025.4.23.1" at the time of writing.
347-
348346
---
349347

350348
> [!TIP]
351349
> You can verify the package was successfully added by examining your `DungeonSlime.csproj` file, which should now contain a reference like:
352350
>
353351
> ```xml
354-
> <PackageReference Include="Gum.MonoGame" Version="2025.4.23.1" />
352+
> <PackageReference Include="Gum.MonoGame" Version="2025.5.5.1" />
355353
> ```
356354

355+
> [!IMPORTANT]
356+
> This tutorial uses version `2025.5.5.1` of Gum, which is the latest version of Gum as of this writing. That exact version is specified to use in the section above when installing the NuGet package to ensure compatibility throughout this tutorial. If there are newer versions of Gum available, please consult the [Gum documentation](https://docs.flatredball.com/gum/gum-tool/breaking-changes) before updating in case there are any breaking changes from the code that is presented in this tutorial.
357+
357358
### Adding UI Sound Effect
358359

359360
To make our UI more responsive and engaging, we will add audio feedback that plays when players interact with buttons and other UI elements. Sound effects provide immediate confirmation that an input has been recognized, creating a more engaging experience.
@@ -446,15 +447,17 @@ Our title panel includes two buttons positioned at the bottom corners of the scr
446447
> [!NOTE]
447448
> Notice how we use `Anchor` to position the buttons relative to the panel's edges, with the "Start" button anchored at the bottom left and the "Options" button anchored at the bottom right. Then the positioning of the elements is adjusted relative to its anchor point.
448449

449-
Each button registers a `Click` event handler to respond when the players selects it, we should implement the event handler method for these buttons next.
450-
451-
Add the following methods to the `TitleScene` class:
450+
Each button registers a `Click` event handler to respond when the players selects it, we should implement the event handler method for these buttons next. First we will implement the handler for the "Start" button. Add the following method to the `TitleScene` class after the `CreateTitlePanel` method:
452451

453452
[!code-csharp[](./snippets/titlescene/handlestartclicked.cs)]
454453

454+
When the "Start" button is clicked and this method is called, it will play the UI sound effect for auditory feedback then change the scene tot he game scene so the player can start playing the game.
455+
456+
Next is the handler for the "Options" button. Add the following method to the `TitleScene` class after the `HandleStartClicked` method:
457+
455458
[!code-csharp[](./snippets/titlescene/handleoptionsclicked.cs)]
456459

457-
These handlers are called when the `Click` event is raised for each button. The handler for the "Start" button changes to the game scene, while the handler for the options button toggles the visibility between the main menu and the options panel.
460+
When the "Options" button is clicked and this method is called, it will play the UI sound effect for auditory feedback then hide the title panel and show the options panel.
458461

459462
#### Creating the Options Panel
460463

@@ -466,19 +469,35 @@ Add the following method to the `TitleScene` class:
466469

467470
This panel includes a text label, two sliders for adjusting audio volumes, and a back button for returning to the main menu. The panel is initially invisible since we start on the main menu. Both the "Music Volume" slider and the "Sound Effects Volume" slider register events to be called when the value of the sliders change and when the value change has been completed. The "Back" button registers a click event similar to the ones from the main menu.
468471

469-
Now we should implement the event handlers for these controls. Add the following methods to the `TitleScene` class after the `CreateOptionsPanel` method:
472+
Now we should implement the event handlers for these controls. First, we will implement the handler for when the value of the sound effect volume slider changes. Add the following method to the `TitleScene` class after the `CreateOptionsPanel` method:
470473

471474
[!code-csharp[](./snippets/titlescene/handlesfxsliderchanged.cs)]
472475

476+
When the value of the "Sound Effects Volume" slider changes and this method is called, a reference to the slider is captured and then the the global sound effect volume is adjusted based on the value of the slider.
477+
478+
Next is the handler when the "Sound Effects Volume" slider has completed a value change. Add the following method to the `TitleScene` class after the `HandleSfxSliderChanged` method:
479+
473480
[!code-csharp[](./snippets/titlescene/handlesfxsliderchangecompleted.cs)]
474481

482+
When the value of the "Sound Effects Volume" slider has completed a change and this method is called, it plays the UI sound effect to provide auditory feedback so the player can hear the difference in volume.
483+
484+
After this is the handler for when the "Music Volume" slider value changes. Add the following method to the `TitleScene` class after the `HandleSfxSliderChangeCompleted` method:
485+
475486
[!code-csharp[](./snippets/titlescene/handlemusicslidervaluechanged.cs)]
476487

488+
Similar to how we handled the "Sound Effect Volume" slider value changes, when the "Music Volume" slider value changes and this method is called, a reference to the slider is captured and then the global music volume is adjusted based on the value of the slider.
489+
490+
Next is the handler when the "Music Volume" slider value has completed a value change. Add the following method to the `TitleScene` class after the `HandleMusicSliderValueChanged` method:
491+
477492
[!code-csharp[](./snippets/titlescene/handlemusicslidervaluechangecompleted.cs)]
478493

494+
When the value of the "Music Volume" slider has completed a change, the UI sound effect is played to provide auditory feedback.
495+
496+
Finally, we need to add the handler for when the "Back" button is clicked on the options panel. Add the following method to the `TitleScene` class after the `HandleMusicSliderValueChangeCompleted` method:
497+
479498
[!code-csharp[](./snippets/titlescene/handleoptionsbuttonback.cs)]
480499

481-
These handlers update our audio settings in real-time as the player adjusts the sliders.
500+
This method plays the UI sound effect for auditory feedback, then hides the options panel and shows the title panel.
482501

483502
> [!TIP]
484503
> Notice that for both sliders, we registered a method for the `ValueChangeCompleted` event. This is so we can play the UI sound effect only when the player has finished adjusting the slider value. If we had instead played the UI sound effect in the `ValueChanged` event, then the UI sound effect would trigger constantly while the slider is being adjusted if using a mouse to drag it.
@@ -540,7 +559,7 @@ Next, add the following fields to the `GameScene` class:
540559
541560
#### Pausing the Game
542561
543-
To pause the game, first we will create a method that makes the pause panel visible. Add the following method to the `GameScene` class after the fields:
562+
To pause the game, first we will create a method that makes the pause panel visible. Add the following method to the `GameScene` class after the `CheckGamePadInput` method:
544563
545564
[!code-csharp[](./snippets/gamescene/pausegame.cs)]
546565
@@ -554,7 +573,7 @@ Finally, update the `CheckGamePadInput` method so that when the start button is
554573
555574
#### Creating the Pause Panel
556575
557-
Next, we will create a method that builds our pause panel with resume and quit buttons. Add the following method to the `GameScene` class:
576+
Next, we will create a method that builds our pause panel with resume and quit buttons. Add the following method to the `GameScene` class after the `LoadContent` method:
558577
559578
[!code-csharp[](./snippets/gamescene/createpausepanel.cs)]
560579
@@ -572,7 +591,7 @@ This method as well plays the UI sound effect for auditory feedback, then quits
572591
573592
#### Initializing the Game UI
574593
575-
Now that we have implemented the method to create the pause panel, we can implement the main UI initializations method that will call them. Add the following method to the `GameScene` class after the `CreatePausePanel` method:
594+
Now that we have implemented the method to create the pause panel, we can implement the main UI initializations method that will call them. Add the following method to the `GameScene` class after the `HandleQuitButtonClicked` method:
576595
577596
[!code-csharp[](./snippets/gamescene/initializeui.cs)]
578597

0 commit comments

Comments
 (0)