Playing sound FX and music in Stencyl

Well done! You have now successfully imported both music and sound FX files. Now all that remains is to trigger them in the code. Perform the following steps to do so:

  1. Open up the Player Handler behavior, and in the events pane, switch to Created, as shown in the following screenshot:
    Playing sound FX and music in Stencyl
  2. In the blocks palette, go to Sound & Images | Sound | Playback, then drag out a Play Sound block, and add it to the stock of blocks in the when created event block, as shown in the following screenshot:
    Playing sound FX and music in Stencyl
  3. Change Play to Loop, as shown in the following screenshot:
    Playing sound FX and music in Stencyl
  4. Navigate to Sound | Choose Sound, as shown in the following screenshot, then select Country Music, and click on OK to commit, as shown in the following screenshot:
    Playing sound FX and music in Stencyl

Now, when we test the game, Country Music will start looping at the beginning of every game level! Next, we need to trigger the Whip Away Sound FX whenever we whip a rock. Perform the following steps to do so:

  1. In the events pane, go to Custom Block in the events list to the left, press F2 and rename it to Whip, as seen in the following screenshot, to keep all of the event labels clear and distinct. Add a Play Sound block to the stack of blocks, which has already been added:
    Playing sound FX and music in Stencyl
  2. In this case, we'll leave Play unchanged, as it would not be desirable to have this sound FX loop.
  3. Navigate to Sound | Choose Sound, and select Whip Away.

That's it, my friend! Test the game, and you should hear music looping in the background from the very start. What's more, when you click on the rocks, you'll hear the Whip Away sound FX!

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

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