top of page
Search

Creating a Game Timer and UI

  • Abbie Hipwell
  • Apr 7, 2022
  • 2 min read

Updated: Jun 15, 2022

During out Beta Test we received a lot of feedback regarding the duration of the match; most players foundt that the barrier was going back and forth too much, and the majority of matches were lasting to a minimum of around five to ten minutes. As our game is supposed to be fast-paced and competetive, we want to limit the amont of time the players have so that each match does not drag out and becoming boring.


To combat this the group came up with the idea of setting a limit to the length of each game, if no one has won by this point the winner will be determined by checking who moved the barrier the furthest, or who wins overtime.


The code for creating a timer can be seen down below ...



The timer code starts with an Event Tick which is called on every frame of gameplay. This allows the timer to be updated correctly.







The timer works by setting the integer variables Seconds and Minutes in the details panel. Once the game has started, and while the Boolean Timer Finished is set to False, the timer will begin counting down;


The timer works by checking whether Seconds and Minnutes are equal to zero, if these are both True, then the Boolean Timer Finished will be set to True, this stops the timer from running and begins Overtime.


If Seconds are not equal to zero, then its value will decrease in increments of one, this is so that the seconds will continue decreasing from 59 until it gets to 0.


If Seconds are equal to zero, and the Minutes are not equal to zero, then the Seconds will be reset back to 59 - restarting the countdown for seconds. Minutes will then also be be reset to Minutes - 1.


Here is the main code from the timer.




To code the UI for the timer, I simply binded the text in the widget to the code to the left, which takes the time from the blueprint above, and converts it into an integer, which can be displayed in the UI.




This is how the final game timer looked ...


The group have been testing out the timer and we have decided to limit the match time to around 1:30 - 2 minutes, this gives the players a good amount of time to try and win, whilst also not lasting so long that they get bored.


















Comments


bottom of page