Time for action – adding a soundtrack

The game file to import and load for this session is 5961_08_04.stencyl.

  1. Download Stencyl Book Sound Track from StencylForge, then close the tabs for the soundtrack and StencylForge.
  2. Open the Sound Management scene behavior and create a new hidden Boolean attribute (not a game attribute) called Sound Track Playing.
  3. Add a new custom event to the Sound Management behavior, called Play Sound Track, and configure it as shown in the following screenshot:
    Time for action – adding a soundtrack
  4. Open the Main Menu scene and add a new when created event (click on the gray Events button at the top of the main panel, then click on +Add Event | Basics | When Creating).
  5. Rename the event to Trigger Sound Track and configure it as shown in the following screenshot:
    Time for action – adding a soundtrack
  6. Test the game play the game and enjoy the soundtrack!

What just happened?

We've added a soundtrack, which plays automatically when the game first loads!

After downloading the soundtrack from StencylForge, we created a new Boolean attribute in the Sound Management behavior. This attribute will be used to determine whether or not the soundtrack has already been started. Although we don't need it at the moment, it's a good idea to monitor the playing status of the soundtrack, so it will be easier to manage if more advanced sound features are added into the game in the future.

With the Sound Track Playing attribute in place, we then created a custom event called Play Sound Track, which listens for the PlaySoundTrack trigger. When the trigger occurs, this event checks that we haven't already started the soundtrack, and if we haven't, it starts playing the music in a loop , which means that it will start again as soon as it ends.

Our final step was to trigger the PlaySoundTrack event, and we did this by adding a when created event to the Main Menu scene. Now, as soon as the game loads, the soundtrack will be triggered after a one-second delay. A delay has been implemented to ensure that all the scene's attached behaviors have been activated and have completed their initialization tasks before attempting to trigger the soundtrack event. If the Main Menu scene attempts to trigger the PlaySoundTrack event before the Sound Management behavior has initialized, then the soundtrack will never play!

Note

The issue of delaying the starting of events in Stencyl is one to look out for! If, during development, a behavior just doesn't seem to be doing its job when a scene is first loaded, then consider if a delay or some other logic may be required to ensure that associated events have enough time to be processed first.

Have a go hero

The game file to import and load for this session is 5961_08_05.stencyl.

We've now implemented some sound effects and a soundtrack, but there are many other sound-management features that we could add to our game.

Have a go at implementing the following:

  • Muting all sounds when a specific key is pressed on the keyboard
  • Allowing the player to choose whether to mute the sound effects, the soundtrack, or both
  • When a level is successfully completed, fade out the main soundtrack and play a jingle
  • Fade out the soundtrack and play an appropriate sound effect when the monkey runs out of lives
  • When all levels have been completed successfully, fade out the main soundtrack and play a different soundtrack

Research popular games and review how they manage sounds from the point of view of the player

Finally, take time to review the available instruction blocks that relate to sound management in Stencyl, and be aware that there are also two very useful sound-related events available (+Add Event | Sounds).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.4.181