Please update your browser
Your browser version is not supported by this site. CS First may not work properly.
You can now draw in your game!
But, you probably noticed that there’s no way to stop drawing.
When you draw in real life, you lift and lower your pencil to start and stop drawing, but
this game keeps the pencil down and drawing all the time.
As a computer scientist, it's important that you plan your project with the user in mind.
In this case, that means making your game fun and easy to play
In this video, you’ll use an if/else statement to program the pencil sprite so it draws only
*if* the mouse button is pressed down.
Otherwise, it won’t draw.
Start by dragging out an “if/else” block.
The pencil should only draw *if* the mouse button is pressed down.
Click sensing, and drag a "mouse down" block into the condition part of the "if" block.
If the mouse is button is pressed down, then the pencil should also be down and ready to
Drag the "pen down" block into the "then" part of the if statement.
Once the mouse button is no longer pressed down, the pencil should be up and should stop
Click the pen menu, and drag a "pen up" block into the "else" part of the "if" statement.
You can read this block as, "if the mouse button is pressed down, then pen down.
Else, or otherwise, pen up."
This code won’t do anything unless you tell the computer when to run it.
It should run for the entire program, so drag the blocks into the forever loop you programmed
Try it out.
Click the flag, and draw something.
*If* the mouse button is pressed down, then the pen is down and draws.
Otherwise, the pen is up and doesn’t draw.
Now it’s your turn!
Use an if else block, so *if* the mouse is down, then the pen is down and draws, else
the pen is up and stops drawing.
Place the if/else statement in the forever loop you programmed earlier.