In this add-on, you will add musicand a volume-control slider to your project.
The music will play when the Play sprite is clickedand the user will control the volumeby clicking the Volume sprite.
To start, select the Volume sprite.
You can add music from the Scratch library.
To add music from the Scratch library,select the Sounds tab, click Choose Sound from Library,and select a sound.
When the Play sprite is clicked, it broadcasts a message.
To make the Volume sprite receive that messageand start playing music, add a When I Receive blockand select the Play message from the drop down menu.
Add a Play Sound block and select the soundyou just picked from the drop down menu.
That's pretty coolbut it would be even more impressiveif the users could control the volumeof the music in the project.
To enable the user to adjust the volumeby clicking the Volume sprite,place a Set Volume block from the Sounds menuunder the Play Sound block.
Right now the volume is set at 100%.
To enable the user to change the volume,select the Variable menuand click Make A Variable.
Name the variable Volume.
Add the Volume variable to the Set Volume block.
To make the Volume slider show upwhen the user clicks the Volume sprite,check the box next to the Volume variablein the scripts menu and double clickthe variable display on the stageuntil the slider display shows up.
Move the slider next to the Volume sprite on the stage.
Try it out.
Click the Play sprite to start the music.
Adjust the volume using the slider.
The volume doesn't change.
When the Volume sprite receives the play message,it sets the volume once.
To enable the user to adjust the volumeat any point after the play message is received,place a forever loop around the Set Volume blockto continually check the volume level the user has set.
Test it out.
Sweet, it works.
Now it's your turn.
Add sound to your projectand add code that lets the useradjust the volume with a variable slider.