The game file to import and load for this session is 5961_08_01.stencyl
.
Sound Management
.Jump SFX
and configure the event as shown in the following screenshot, ensuring to set the event's trigger name to JumpSFX
:Trigger Jump SFX
, and configure it as shown in the following screenshot, ensuring that Control is set to up. Note that the blue Jumping block is an attribute that is used in the Jump and Run Movement behavior (Attributes | Getters in the palette):We've just added a jumping sound effect to the game!
The very first task was to remove the Game Over scene, because our game no longer uses it. Then, after downloading the sound effect from StencylForge, we created a new scene behavior called Sound Management
, and attached it to all the scenes in our game; we may need to have sounds playing in scenes other than the playable levels.
We then created a new custom event called Jump SFX
in the Sound Management
scene behavior, which simply plays the specified sound effect on channel 1 when it is triggered. Further information about sounds and channels can be found in the following section entitled, Examining the play sound instruction blocks.
Our next step was to open the Jump and Run Movement
behavior and add a new keyboard event. This event called Trigger Jump SFX
waits for the up
control to be pressed, and when that happens, it triggers the JumpSFX
custom event in the Sound Management
behavior. However, we placed the trigger inside an instruction that checks if not Jumping
; this is shorthand for if Jumping is not = true
, and is just a different way of carrying out the same test.
Why are we checking to see if the Jumping
attribute in the Jump and Run Movement
behavior is not true? Because we didn't create this behavior (it is one of the ready-made behaviors that is provided with Stencyl), a little research was required to find out how the jumping routines worked! It isn't necessary to fully understand the behavior in detail, but if we examine the main always
(when updating) event in the Jump and Run Movement
behavior, we can see that there is an attribute called Jumping
that is set when (surprise!) the actor is jumping. We can also see attributes called Jump
and On Ground
, as shown in the following screenshot, which is an excerpt from the
Jump and Run Movement
behavior:
With this information, we might surmise that the Jumping
attribute is set to true
when the actor is jumping, and that it is set to false
when the actor is no longer jumping.
We only want the jumping sound effect to be played when the player presses the up
control and the actor is not already jumping, otherwise repeated presses of the up
control will cause the sound effect to play, even when the monkey is already in the air, and that will just be annoying for players of our game!
Testing the game demonstrates that, however many times the player presses the up
control, the jumping sound effect will only be played if the monkey is not already jumping. Perfect!
The game file to import and load for this session is 5961_08_02.stencyl
.
Currently, the jumping sound effect will still play when the game is paused and the player presses the up
control.
Jump SFX
custom event, so the sound effect will not occur when the game is pausedA suggested solution is provided in the download file 5961_08_03.stencyl
, along with comments in the Jump SFX
event of the Sound Management
scene behavior.
18.118.32.213