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.
Add code to the ‘X-block’ sprite to clear the Stage when the sprite clicked.
You don’t need to use a
to clear the Stage, because the broadcast
erase all
block does that job.
Do you see that the pencil sprite includes an eraser costume?
Your project also includes a separate eraser sprite.
Click on this eraser sprite and then select show.
Here is how your Stage should look now:
Add code to the eraser sprite to send an 'eraser' broadcast
when the eraser sprite is clicked.
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.
There’s one more problem with the pencil: you can draw anywhere on the Stage, including near the ‘clear’ and eraser buttons!
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
:
Test your project. You now should not be able to draw near the buttons.