In this lesson we are going to make the button clickable so when the button is clicked, the game restarts. It will look like this:
To do this, add a new:
- Event selecting Touch > On tapped object and select the Button
- Action on the Button > Tween > and tween the opacity to 50 and set the time to 0.5 seconds (we’re basically repeating the actions that happen after the carrots are clicked)
- Action on System > Wait 0.5 seconds
- Action on System > Restart layout
The event we have just set up should look like this:
Set On Start of Layout Event
There’s one more thing to do and that’s to add a new System event. This time we want System > One start of layout and then set a new action for System > Set value and set g_count to 0.
Drag this event to the top of the page (while there’s no need to do this, as the system recognizes that this event should happen first, I personally like to keep the ‘on start of layout’ events at the top of the page for easy reference).
The event sheet will now look like this: