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 code a sprite to glide on stage using a “broadcast” block.

First, choose the object you want to use. Click on the Object sprite. Click the Costumes tab and choose a costume you want to use. To start, program the object sprite to glide on the stage. In this example, the sprite appears on the left side of the stage and glides toward the android sprite. Select the object sprite and drag it to the left of the stage. Then, click the motion menu, and drag out a “go to xy” block.

This block sets the sprite’s x and y position, making it appear at that spot when the block is run. Great. This should happen at the start of the program, so click on the events menu, and add a “when flag clicked” event. Next, drag the object sprite to where you want it to go. Notice that the x and y positions of the object sprite changed. The values in the “glide” block also updated to the sprite’s current position. Drag out a “glide” block. To test, click the “go to xy” block. The object starts at the left side of the stage. Then, click on the “glide” block. The sprite glides to the next position.

Now, send a message to start the “glide” action by broadcasting a message. The “broadcast” block sends a message, and the “when I receive” block receives it. “Broadcast” blocks allow you to make code run whenever you’d like in your program.

In this example, the object will glide when the android mentions it.

Select the android, go to the events menu, and add a “broadcast” block above the “say” block that mentions the object. Click the dropdown menu, and select “new message.” Name the message something that describes what the code will do. This example uses “object appears.” Then, click the object sprite. From events, add a “when I receive” block above the “glide” block. Test this by clicking the flag. Great! When the broadcast block runs, it tells the “glide” block to run.

Finally, the object should hide at the beginning of the program, then show when the message is received. From looks, drag a hide block under the “when flag clicked” block. Then, add a “show” block under the “when I receive” event. Click the flag to test.

Awesome! Now, it’s your turn.

Make the object glide on the stage using “go to xy” and “glide” blocks Make your code run using “broadcast” and “when I receive” blocks.

And finally, make your object appear using “show,” and “hide” blocks.

Scegli un’estensione
Oggetti che appaiono
Nuvoletta (Part 1 of 2)
Nuvoletta (Part 2 of 2)
Mania del colore
arrow_backward Indietro
Avanti arrow_forward
Istruzioni
  1. Scegli un componente aggiuntivo e fai clic su "Guarda" per scoprire come costruirlo.
  2. Una volta terminato un componente aggiuntivo, scegline un altro da provare!