SCRATCH GOLD II
SCRATCH GOLD I
2 of 3

5.05 Undo mistakes

Sometimes mistakes happen, so add a ‘clear’ button and an eraser button.

Add the ‘X-block’ sprite from the library’s letters section. Colour the sprite’s costume in red and make it a little smaller. This sprite is the ‘clear’ button.

Click on Choose a Sprite to open the Sprite Library:

The 'Choose a Sprite' icon highlighted.

You can search for a sprite, or browse for one by category. Click on a sprite to add it to your project.

The Sprite Library.
screenshot

Add code to the ‘X-block’ sprite to clear the Stage when the sprite clicked.

cross

You don’t need to use a broadcast to clear the Stage, because the erase all block does that job.

Do you see that the pencil sprite includes an eraser costume?

screenshot

Your project also includes a separate eraser sprite.

Click on this eraser sprite and then select show.

screenshot

Here is how your Stage should look now:

screenshot

Add code to the eraser sprite to send an 'eraser' broadcast when the eraser sprite is clicked.

eraser

When the pencil sprite receives the ‘eraser’ message, it should switch its costume to the eraser and switch the pen colour to white, which is the same colour as the Stage!

Add some code to create the eraser.

Test your project to see if you can clear the Stage and erase pencil lines.

screenshot

There’s one more problem with the pencil: you can draw anywhere on the Stage, including near the ‘clear’ and eraser buttons!

screenshot

To fix this, change the code so that the pen is only down if the mouse is clicked and the y position of the mouse pointer is greater than -120:

pencil

Test your project. You now should not be able to draw near the buttons.

screenshot
×
×

Cart