In this add-on, you will program music
to fade in and out during your project.
To start, add a music loop to your project.
Then drag out a play sound until done block
into the script editor,
and add a forever loop around this block.
Add a one flag click block to the top of the stack.
The music should start relatively low or quiet,
then get louder.
Drag out a set volume block from the Sound menu
and place it under the one flag clicked block.
Tinker with the value to set the volume of the music
at the start of the project.
This example uses 4%.
Next, add a change volume block.
Use a positive number to make the volume increase gradually.
A smaller number will make the music fade in more slowly.
This example uses 0.5.
The volume should get louder
until it reaches a certain point.
So add a repeat until block around the change volume block.
Next, place a greater than operator in the condition field.
Put a volume block from the Sound menu in the first blank.
The code now reads, change the volume by 0.5
until the volume is greater than a certain number.
This example uses 80% in the greater than operator.
Next, tell the music when to fade in.
Add a broadcast block to the top of the code stack
that animates the Android.
Name the message something that makes sense.
This example uses, music fade in.
Then add a when I receive message block
to the repeat until block.
To program the music to fade back out,
duplicate the fading in code stack.
Switch the greater than operator to a less than operator,
and change the value to a small number
to set the minimum volume.
This example uses four.
Next, edit the change volume block to a negative number.
This example uses negative 0.5.
Great, now, tell the music when to fade out.
Drag a broadcast block somewhere near the end
of the animation code, and name the message
something that makes sense, like, music fade out.
Then change the dropdown menu on the when I receive block
to the name of your message.
Now, the music fades in, plays throughout the story,
then fades out.
Now, it's your turn.
Program a song to play forever during your story.
Program the music to fade in and out.
Cue the music to fade in and out using broadcast
and when I receive blocks.
Program a sunrise or sunset for your story.
Program objects to fall from the sky.
Add background music which fades in and out.
Add a slow motion effect to your android.
Use the drawing tools to add your own animation.
Interact with the user of your program.
Sign in to save your project and track your progress.