Time for action – displaying a timer bar

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

  1. Open the Score Management scene behavior and click on the Display HUD event.
  2. In the when drawing event, right-click on the blue block that draws the text for the countdown timer and select Activate / Deactivate from the pop-up menu. Note that the block becomes faded.
  3. Locate the draw rect at ( x: 0 y: 0 ) with ( w: 0 h: 0 ) instruction block in the palette, and insert it at the bottom of the when drawing event.
  4. Click on the draw option in the newly inserted block and change it to fill.
  5. Set both the x: and y: textboxes to 10.
  6. Set the width (w:) to Countdown x 10.
  7. Set the height (h:) to 10.
  8. Ensure that the draw text … block and the fill rect at … block in the Display HUD event appear as shown in the following screenshot (the draw text LIVES: … block may look different if the earlier Have a go hero section was attempted):
    Time for action – displaying a timer bar
  9. Test the game!

What just happened?

We have created a timer bar that displays the amount of time remaining for the player to collect the fruit, and the timer bar reduces in size with the countdown!

First, in the Display HUD event we deactivated, or disabled, the block that was drawing the textual countdown message, because we no longer want the text message to be displayed on the screen.

The next step was to insert a draw rect … block that was configured to create a filled rectangle at the upper-left corner of the screen and with a width equal to the value of the Countdown timer multiplied by 10. If we had not multiplied the value of the countdown by 10, the timer bar would be very small and difficult to see (try it)!

We'll be making some improvements to the timer bar later in this chapter.

Activating and deactivating instruction blocks

When we deactivate an instruction block, as we did in the Display HUD event, it no longer functions; it's completely ignored! However, the block remains in place, but is shown slightly faded, and if required, it can easily be reenabled by right-clicking on it and selecting the Activate / Deactivate option.

Being able to activate and deactivate instruction blocks without deleting them is a useful feature — it enables us to try out new instructions, such as our timer bar, without having to completely remove blocks that we might want to use in the future. If, for example, we decided that we didn't want to use the timer bar, we could deactivate it and reactivate the draw text … block!

Note

Deactivated instruction blocks have no impact on the performance of a game; they are completely ignored during the game compilation process.

Have a go hero

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

Note

The tasks in this Have a go hero session are optional; failure to attempt them will not affect future tutorials.

Referring to Stencyl's online help if required at www.stencyl.com/help/, try to make the following improvements to the timer bar:

  • Specify a more visually appealing color for the rectangle
  • Make it thicker (height) so that it is easier to see when playing the game
  • Consider drawing a black border (known as astroke) around the rectangle
  • Try to make the timer bar reduce in size smoothly, rather than in big steps

Ask an independent tester for feedback about the changes and then modify the timer bar based on the feedback.

Note

To view suggested modifications together with comments, review the Display HUD event in the downloadable files that accompany this book. The file that contains the modifications suggested above is named 5961_06_09.stencyl.

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

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