Sometimes it is desirable to make a sound fade out. We'll continue by building code similar to other recipes in this chapter and then fading the sound out.
Note
You could do this with notes, drums, or just general sounds. It all still applies just the same!
Open a new file and create the following code. If you need a reference, see the first few recipes of this chapter:
To get working on creating a volume fade, follow these steps:
- Drag over a new block.
Attach a wait () secs block from the Control category and change the time to
20
.Drop a forever loop below this.
Return to the Sound category. Drop a change volume by () block into the forever loop you just created.
Change the numerical value to
-5
.Return to the Control category and drop a wait () secs block below the Sound block you just dragged in.
Change the wait time to
0.5
seconds.You should have the following code that will play for 20 seconds and then begin to fade out.