Creating a countdown timer

In this recipe, we will look at one possible way to create a countdown timer from 60 to 0 seconds that the player will see on-screen.

How to do it...

  1. Begin by placing an AreaTrigger entity onto the map to use as the container for the Flow Graph.
  2. In the RollupBar, click on the Entities button.
  3. Under the Triggers section, select the AreaTrigger.
  4. Right-click the newly placed AreaTrigger and create a new Flow Graph. Name the Flow Graph as CountDownTimer.
  5. With the Flow Graph open and the new AreaTrigger selected, add in the following nodes:
    • Game:LocalPlayer
    • HUD:DisplayDebugMessage
    • Misc:Start
    • Math:SetNumber
    • Math:Sub
    • Time:Timer
    • Math:Counter
    • Math:Equal
  6. Set Time:Timer period=1.
  7. Set Math:SetNumber in=60.
  8. Set Math:Equal B=60.
  9. Link the Flow Graph together as follows:
    • Game:LocalPlayer entityId out to HUD:DisplayDebugMessage Choose Entity in
    • Misc:Start output out to Math:SetNumber set in
    • Math:SetNumber out out to Math:Sub A in
    • Time:Timer out out to Math:Counter in in
    • Math:Counter count out to Math:Sub B in
    • Math:Counter count out to Math:Equal A in
    • Math:Equal true out to Time:Timer paused in
    • Math:Sub out out to HUD:DisplayDebugMessage Show AND message in
  10. The resulting Flow Graph should look like the following:
    How to do it...countdown timercreating

How it works...

A simple use of the timer and math counter outputs the value that is used to subtract from the 60 value from Math:SetNumber. As soon as the counter reaches 60, the Math:Equal node sends a signal to the timer to pause itself and stop the count at 0.

There's more...

One addition to this could be the node of Math:Round. Linking the result of the Math:Sub to the In input of this node and linking the outRounded value to the HUD:DisplayDebugMessage will round the numbers down to an integer.

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

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