Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

4. Creating Stamps

Transcript

In this screencast, you will program the clone to follow the mouse when clicked and to stamp itself. Right now, the clone’s actions match the sprite’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 the mouse 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, but you 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 “mouse down” block inside the “repeat until” loop. Make sure the “repeat until” block is 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 pointer until the mouse is clicked. Great!

Keeping track of lots of clones can slow down your program, and the project only needs this clone 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 computer knows 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. When that 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, fix this 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 pointer until it is clicked using a “repeat until” loop, a “go to mouse pointer” block, and a “mouse down” condition. 3. Make the sprite “stamp.”

4. After the clone stamps, “delete this clone.”

Add some wait time before the loop runs.

arrow_backward Back
Next arrow_forward
Instructions
  1. Make the clone do something different from the building block sprite.
  2. Make the clone follow the mouse pointer until the mouse button is pressed down again.
  3. Make the sprite stamp.
  4. Keep the program from getting bogged down.