Time for action – displaying the game over banner

The game file to import and load for this session is 5961_07_15.stencyl.

  1. Download the Stencyl Book Game Over Banner and the Stencyl Book Play Button actors from StencylForge.
  2. Set the physics properties for both the actors so that they cannot be moved or paused.
  3. Ensure that the Stencyl Book Play Button tab is currently selected, and click on the Events button in the row of gray buttons above the Animation Editor panel.
  4. Click on + Add Event | Input | On Actor to add a new input event and rename it to Clicked, then modify the event so that it appears as shown in the following screenshot, remembering that the purple blocks are game attributes:
    Time for action – displaying the game over banner
  5. Open the Score Management scene behavior, and in the left-hand panel, right-click on the Display Success Banner event name and select Duplicate, then rename the newly duplicated event to Display Game Over Banner.
  6. Modify the new Display Game Over Banner event as shown in the following screenshot, ensuring that the event's trigger name is changed to DisplayGameOverBanner, and both of the set… instructions are updated:
    Time for action – displaying the game over banner
  7. Open the actor behavior named Health and select the Show Angel event in the left-hand panel.
  8. Deactivate the switch to Game Over… instruction block in the orange otherwise block at the bottom of the event, and insert the trigger block shown in the following screenshot:
    Time for action – displaying the game over banner
  9. Test the game; make the monkey lose all its lives and test the Play button!

What just happened?

We have utilized the reusable DisplayBanner event to display a game over banner when the player loses all their lives.

In order to create our customized banner, we downloaded the two actors from StencylForge that contained the required images for the game over banner and the play option button, and we configured their physics settings so that they will always remain onscreen and cannot be paused. We also attached a custom event to Stencyl Book Play Button, which, when clicked, resumes the game with the unpause game block, resets the lives to 3 and level number to 1, then switches to the Level1 scene so that the game restarts.

We then duplicated the DisplaySuccessBanner event, renamed the duplicate to DisplayGameOverBanner, and modified the duplicated event to specify Stencyl Book Game Over Banner as Required Banner, and Stencyl Book Play Button as Required button. We could have created the DisplayGameOverBanner event manually block-by-block, but as we had an existing event that did a very similar job, it made sense to duplicate it and then modify its settings—after all, we know that the original DisplaySuccessBanner event already worked perfectly!

The next step was to update the Show Angel event to display the game over banner when the monkey runs out of lives. Previously, when the monkey ran out lives, we immediately switched to the Game Over scene. But we no longer want to do that, so we deactivated the switch to Game Over… block, and added an instruction to trigger the DisplayGameOverBanner custom event in the Score Management scene behavior.

Now, when our monkey runs out of lives, the DisplayGameOverBanner event is triggered and it specifies the correct banner and option button, and then triggers the general-purpose DisplayBanner event. The DisplayBanner event displays the correct banner and option button; in this case, it's the Stencyl Book Game Over Banner and Stencyl Book Play Button. When the Play option button is clicked, the Lives and Level game attributes are reset, and the game switches to Level1, so the player can start over from the beginning!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.254.48