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’ll program the sprite to dance while wearing the fitness gadget.

First, click the android sprite, select the "looks" menu, and drag out a “change color effect" block. This block changes the graphic effect on a sprite. Click the dropdown menu, and select “whirl effect." Click on it to try it out! The sprite dances to the right.

If you keep clicking this block, the sprite continues "dancing" to the right. Click the stop button to reset the sprite. To make the sprite dance to the left, drag out another “change whirl effect” block. This time, change its value to negative twenty five. Try it out. That’s not bad. The sprite dances to the left.

A dance is more fun if you put all the moves together. To do this, snap both “change whirl effect” blocks together. The block stack should now make the sprite dance to the right, then to the left. Try it out! Hmm, nothing happens because there's no gap or wait time between the blocks. The sprite dances so fast that you can’t see it.

To slow it down, drag out two “wait” blocks from the control menu. Snap one after each of the the "change effect" blocks. Now, when you click on the block stack, you can actually see the sprite do its dance.

To change how fast the dancer moves, change the value in the “wait” block. Lower values will make the sprite move faster, and higher values will make it move slower. Try 0.2 seconds, or plug in different values until you find one that you like.

Cool. The sprite dances, but only to the right, instead of to the right and then to the left like expected. That’s because the “change effect by 25” block makes the sprite dance to the right, and the second “change effect by negative 25” block makes the sprite go back to normal. Add a “change whirl effect by negative 25” block to make the sprite dance to the left. Add a “wait” block, then a “change whirl effect by 25” block to make the sprite go back to normal. Add another “wait” block. Try it out. Great!

Now the sprite dances to the right, then to the left.

Next, add a “repeat” block from the control menu around the whole stack to repeat the dance moves a few times. In this example, the sprite will do the dance 6 times, but you can make the sprite dance as many times as you want. Test this code by clicking on it.

That’s pretty awesome. The sprite dances!

To make the sprite dance at the right time in your commercial, use “broadcast and wait” and “when I receive” blocks. A “broadcast” block broadcasts, or sends a message to another part of a program. A “when I receive” event sets up that other part of the program to get the message and run the code that makes something happen. In this case, that’s making the sprite dance. Drag out a “broadcast and wait” block, and place it in the main code stack when you want the sprite to do its dance. Click on the dropdown. There’s no message for dancing, so click on “new message” to create one.

This message needs a name. It will broadcast when the sprite should dance, so name it something descriptive, like “happy dance.” Next, the sprite needs to receive the message.

From the “events” menu, drag out the “when I receive” block, and snap it above the code stack you just created. To make sure the sprite is responding to the right message, check that “happy dance” is selected in the dropdown menu. When the sprite receives the dancing message, it should run the code you created and start dancing.

Great. Now the sprite does the introduction after it gets the message, “introduce product.”

Then, it dances when it receives the “happy dance ”message.

Pretty cool, right? Here's the game plan: Make the sprite dance using the “change effect by,” “wait,” and “repeat” blocks. Send a message from the main code stack to make the sprite dance using “broadcast” and “when I receive message” blocks.

Choose an Add-On
play_circle_filled
Happy Dance
Program the sprite to dance.
arrow_forward
play_circle_filled
Changing Scene
Move the android through different scenes to see how the gadget reacts.
arrow_forward
play_circle_filled
Weatherproof
Add weather effects to show how rugged the gadget is.
arrow_forward
play_circle_filled
Purchase Decision
Ask the buyer to purchase the object.
arrow_forward
play_circle_filled
Admiring Crowd
Add more sprites to the project to interact with the athlete.
arrow_forward
play_circle_filled
Fitness Coach
Code the sprite to have a pulse and talk about its heart rate.
arrow_forward
arrow_backward Back
Next arrow_forward
Instructions
  1. Choose an Add-On, and click "watch" to learn how to build it.
  2. Once you finish one Add-On, try another one below the video!