Now you’re going to add a ‘Play’ button, so that the player can play your game lots of times.
Create a new ‘Play’ button sprite that the player needs to click to start a new game.
You can draw the sprite yourself, or edit a sprite from the library.
Add this code to your button sprite:
The new code includes another
block, which sends the message ‘start’.broadcast
The new code makes the ‘Play’ button sprite show when player clicks on the flag. When the player clicks on the button sprite, the sprite hides and then broadcasts a message that other sprites can react to.
At the moment, the character sprite starts asking questions when the player clicks the flag. Change your game’s code so that character sprite starts asking questions when it receives the ‘start’ broadcast
.
Select your character sprite and, in its code section, replace the when flag clicked
block with a when I receive start
block.
Click the green flag, and then click on the new ‘Play’ button to test whether it works. You should see that the game doesn’t start before you click on the button.
Can you see that the timer starts when the green flag is clicked, instead of when the game starts?
Can you change the code for the timer so that the timer starts when the player clicks on the button?
Add code to your button sprite so that the button shows again at the end of each game.
Test the ‘Play’ button by playing a couple of games. The button should show at the end of each game.
To test the game more quickly, you can change the value of time
so that each game is only a few seconds long.
You can change how the button looks when the mouse pointer hovers over it.