In this screencast, you will program the clone to follow the mouse when clicked and to stampitself. Right now, the clone’s actions match thesprite’s. To program the clone to do something else, use an event.
Drag the “when I start as a clone” event from the control menu into the blocks area.
To make the clone follow the mouse pointer, drag out the “go to mouse pointer” block.
Just like the spray paint sprite on Day 5, however, the clone should keep following themouse pointer, not just go to it once. To make the clone continue performing an action, use a loop.
On Day 2, to animate the sprite forever you used a forever loop.
On Day 3, you animated the mouth a certain number of times, so you used a repeat loop.
Today, you don’t know how many times the sprite should follow the mouse pointer, butyou do know it should keep doing so until the mouse is clicked and not after. Luckily,there is a loop for that - “repeat until.” Place a “repeat until” loop around the“go to mouse pointer” block. Like an “if” block, a “repeat until”block has a space for a condition that will stop the loop from running. In this case,the “mouse down” block is the condition. From the “sensing” menu, place a “mousedown” block inside the “repeat until” loop. Make sure the “repeat until” blockis under the “when I start as a clone” block, so only the clone will move.
Test the code.
When you click the sprite, a clone is created.
The clone then enters the repeat until loop and follows the mouse pointeruntil the mouse is clicked. Great!
Keeping track of lots of clones can slow down your program, and the project only needs thisclone to leave a stamp of itself on the stage. To leave an image of the clone, place a “stamp”block after the “repeat until” loop.
Finally, place a “delete this clone” block after the “stamp” block, so your computerknows it doesn’t have to keep track of the clone anymore.
Test the code. When you click the sprite in the toolbox, it should create a clone. Whenthat clone is created, it should follow the mouse pointer until the mouse is clicked.
At that point, it should leave a stamp of itself. It does!
But, if you try this in fullscreen mode, clicking on the sprite doesn’t seem to create a clone.
When you click on the sprite, the program reacts to the mouse button being pushed down.
So, it ends the loop before the user can drag the sprite anywhere. Just like in Day 6, fixthis by adding a short wait before the loop. Place a “wait” block before the loop,and enter a short amount of time in it,, like 0.2 seconds.
Now, it’s your turn! 1. Program the clone to execute code with a“When I start as a clone” block. 2. Make the clone follow the mouse pointeruntil it is clicked using a “repeat until” loop, a “go to mouse pointer” block, anda “mouse down” condition. 3. Make the sprite “stamp.”