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
> 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 incase there are any breaking changes from the code that is presented in this tutorial.
357
+
357
358
### Adding UI Sound Effect
358
359
359
360
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
446
447
> [!NOTE]
447
448
> 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.
448
449
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:
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:
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 forthe 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.
458
461
459
462
#### Creating the Options Panel
460
463
@@ -466,19 +469,35 @@ Add the following method to the `TitleScene` class:
466
469
467
470
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.
468
471
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:
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:
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:
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:
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:
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.
482
501
483
502
> [!TIP]
484
503
> 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:
540
559
541
560
#### Pausing the Game
542
561
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:
@@ -554,7 +573,7 @@ Finally, update the `CheckGamePadInput` method so that when the start button is
554
573
555
574
#### Creating the Pause Panel
556
575
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:
@@ -572,7 +591,7 @@ This method as well plays the UI sound effect for auditory feedback, then quits
572
591
573
592
#### Initializing the Game UI
574
593
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:
0 commit comments