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 Passing By

Choose an Add-On
play_circle_filled
Starting Point
Set the order in which the objects pass by.
arrow_forward
play_circle_filled
Walk to the Beat
Play music when the character moves.
arrow_forward
play_circle_filled
Day & Night
Change the day to night as the character moves forward.
arrow_forward
play_circle_filled
Passing By
Program the objects being passed to respond to the character.
arrow_forward
play_circle_filled
Scenery Change
Set costumes to a random color when they appear.
arrow_forward
  • 1. Parallax Introduction
  • 2. Scrolling Objects
  • 3. Customize Attributes
  • 4. Add More Objects
  • 5. Add-Ons
  • 6. Reflection
  • 7. Wrap-up: Parallax
  • 8. Wrap-up: Share Your Project
  • 9. Wrap-up: Show Your Project
arrow_backward Back Next arrow_forward
Transcript

In this add-on, you will program the clone of a particular costume to play a sound or say something when it passes the "objects" sprite.

To start, program the clone to check which costume is displayed.

This example uses the peacock costume, but you can use any costume in your project.

Add a "when I start as clone" block.

In this example, if the peacock costume is displayed, then the clone plays a sound and says something.

Add an" if then" block.

Next, check if the costume number equals the costume you want to perform the action using the "equals" and "costume number" blocks.

Program an action that the clone will perform if the correct costume number is displayed.

Add a "say" block or a "play sound" block.

You can add both types of blocks or just one.

Type in a message in the "say" block, or add a sound from the Scratch library.

select a “forever” block, and place it around your block stack.

Click the flag and the right arrow key to test.

Great!

The peacock plays the goose sound and says, "What's up?"

But, it keeps repeating this action for as long as it's on the screen, which is annoying.

To fix this, program the clone to wait until the dog has passed it.

Add a "wait until" block and a “less than” block.

In the left side, add an “x position” block from the motion menu.

In the right side, add an "x position" block from the sensing menu, and make sure the walking sprite's name is selected.

Now the code reads, “if the clone's x position is less than the walking sprite's x position, meaning that the walking sprite has passed the clone, then play the goose sound and say, ‘What's up?’ Click the flag and the right arrow key to test.

Great!

The peacock waits to play its sound until the walking sprite passes it.

But, after the walking sprite passes it, it keeps playing the sound until it is off screen.

To make the clone perform the action only once each time it appears on screen, duplicate the wait until code, and stack it on top of the original wait until code.

Tell the clone to wait until its x position is greater than the walking sprite's x position, then wait until its x position is less than the walking sprite's x position.

This makes the clone wait until the sprite passes it before it plays its sound, then it won't play the sound again until the sprite is in front of it and passes it again.

Click the flag and the right arrow key to test again.

Great!

Now, it's your turn.

Program the clone to check which costume is displayed.

Check if the costume number equals the costume that will perform the action.

Program an action that the clone will do if the correct costume number is displayed.

Program the clone to wait until the sprite has passed it.

Duplicate the wait until code stack and switch the order of the "x position" blocks.