Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

Transcript

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.

This example uses “dance chill out.”

Then, drag a “play sound until done” block into the script editor, and add a “forever” loop around this block.

Add a “when flag clicked” block to the top of the stack.

Test it!

Awesome.

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 “when flag clicked” block.

Tinker with the value to set the volume of the music at the start of the project.

This example uses 4 percent.

Awesome.

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.

This code now reads: change the volume by 0.5 until the volume is greater than a certain number.

The default value is 100 percent.

This example uses 80 percent 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.”

Great.

Then, add a “when I receive message” block to the “repeat until” block.

Test this.

Awesome.

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 4.

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 to 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.

Choose an Add-On
play_circle_filled
Sunrise, Sunset
Program a sunrise or sunset for your story.
arrow_forward
play_circle_filled
Weather
Program objects to fall from the sky.
arrow_forward
play_circle_filled
Music Fade
Add background music which fades in and out.
arrow_forward
play_circle_filled
Slow Motion
Add a slow motion effect to your android.
arrow_forward
play_circle_filled
Draw
Use the drawing tools to add your own animation.
arrow_forward
play_circle_filled
User Input
Interact with the user of your program.
arrow_forward
arrow_backward Back
Next arrow_forward
Instructions
  1. Choose an add-on, and click the "Watch" button to learn how to build it.
  2. After you finish, come back to the add-ons Screen to try another add-on!