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 Costumestab and choose a costume you want to use. To start, program the object sprite to glideon the stage. In this example, the sprite appears on the left side of the stage andglides toward the android sprite. Select the object sprite and drag it to theleft 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 blockis 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 youwant it to go. Notice that the x and y positions of the object sprite changed. The values inthe “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 thestage. 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” blocksallow 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 “newmessage.” Name the message something that describes what the code will do. This exampleuses “object appears.” Then, click the object sprite. From events,add a “when I receive” block above the “glide” block. Test this by clicking theflag. 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 messageis 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” blocksMake your code run using “broadcast” and “when I receive” blocks.
And finally, make your object appear using “show,” and “hide” blocks.