Skip to content

Please update your browser

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

arrow_back Musical Objects

Transcript

In this add-on, you'll add objects to your game that make different sounds as the sprite walks over them.

You can even arrange the objects in different ways so the user can play a song.

Adding unique features for players to discover keeps them engaged and makes your game more enjoyable.

To start, click the flag and move the sprite into the location you want to add the objects.

This example uses the cave.

Then, add a new sprite.

Choose one from the library, or paint your own.

This example, we'll use a small red square.

Drag out a play note block.

Click on it to hear what it sounds like.

(piano key plays)

Cool, it plays the C note.

To change what the note sounds like, add a set instrument block above the play note block, and select the instrument you want to use from the drop down menu.

Play the block stack to hear what the instruments sound like.

Choose one that's appropriate for the setting.

This example uses the vibraphone.

(note chimes)

To make the object play this note when the sprite walks over it, put an if block around the two sound blocks.

Then, place a touching block inside the condition slot, and select the character sprite from the drop down menu.

Add a forever block around the if block so the sprite checks the condition continuously.

Text the code by clicking the stack, then, using the movement keys to make the sprite walk over the object.

(note chimes) Cool, the sound plays!

If the notes are playing too fast, change their duration using the beats bubble inside the play note block.

(note chimes)

Click the flag to test the program.

Oh no, the object appears in town, but it should only appear in the cave!

Fix this by adding two when backdrop switches blocks from the events menu.

Change the drop down in one to town, and change the other to the location where you placed your objects.

Then, open the looks menu and add a hide block under town and a show block under the location you selected.

Snap the forever loop underneath the show block.

Test the code again by clicking the flag.

Great, the object no longer appears in town.

When the sprite enters the cave, the object appears and it makes sound when the sprite walks over it.

(note chimes)

Explore adding more musical objects so the user can play a song.

Duplicate the object by right clicking on it and selecting duplicate.

And the new sprite, change it's appearance.

Drag it to where you want it to appear, and change the note it plays.

Do this as many times as you would like.

Now it's your turn.

Add a new sprite.

Add an instrument and note combination using set instrument and play note blocks.

Make the sound play as the sprite walks over the object using touching, if, and forever blocks.

Make the objects show only in a specific location using when backdrop switches, show, and hide blocks.

Duplicate the sprite and change it's appearance and sound as many times as you'd like.

Choose an Add-On
Peek-a-boo
Make the game more challenging by showing the object only if the character is nearby.
Musical Objects
Add some interactive items that make sound when the character walks over them
Obstacle Obstruction
Make the maps more realistic by preventing the character from running into obstacles, like trees or buildings.
Hide and Seek
Hide the object in a random location each time.
arrow_backward Back
Next arrow_forward
Attributions
  • The song “Magic Marker” is © YouTube-- CC-BY-SA 4.0 does not apply.