Countdown timer bar...

Get help using Construct 3!

Post » Sun Oct 01, 2017 12:08 pm

I've implemented a timer on my game - just a simple:

System > Every 1.0 seconds > System > Subtract 1 from Timer

The timer doesn't start from a fixed time though, I also have events where 5 or 10 seconds are added each round. It all works fine, but I want to replace the countdown text with a bar that decreases in length.

So each round I'm guessing I have to set the start length of the Timer Bar (1400 pxls) to equal the current start Timer value (whatever it may be) and the end length (0 pxls) to equal the lowest Timer value (0 seconds) and on each tick tween the length of the timer bar.

In the layout I've given the Timer Bar two variables - one called Full with a value of 100 and one called Empty with a value of 0. Is this the right way to go or is there a way in the events sheet where I can simply tween the length or width from Timer (full time) to Timer 0?
B
9
S
3
G
3
Posts: 97
Reputation: 2,371

Post » Sun Oct 01, 2017 5:52 pm

You could do:

timerBar.Width = timer*k

where k = timerBar.maxWidth/timerStart

k is a constant and can be calculated once at the start of the layout/round (assuming you're not changing the maximum bar width and the initial timer value on the fly).
B
22
S
9
G
4
Posts: 476
Reputation: 4,327

Post » Mon Oct 02, 2017 11:31 am

mekonbekon wrote:You could do:

timerBar.Width = timer*k

where k = timerBar.maxWidth/timerStart

k is a constant and can be calculated once at the start of the layout/round (assuming you're not changing the maximum bar width and the initial timer value on the fly).


Can you expand on this? Not sure what you mean.
B
9
S
3
G
3
Posts: 97
Reputation: 2,371

Post » Mon Oct 02, 2017 6:24 pm

@Bootfit: something like this:

https://www.dropbox.com/s/hjg2pc3mnrq1h ... r.c3p?dl=0

I've included two methods for representing the timer bar:

1) The red bar's starting length is determined by unitWidthR x timerDuration, i.e. more time = longer bar.

2) The blue bar's starting length is determined by widthMaxB regardless of timerDuration; instead it changes the rate at which it shrinks, i.e. more time = slower bar. This is useful if you have limited room for the bar or want to maintain sizes and positions of your HUD objects.

timerDuration = how long you want the timer to run for
unitWidthR = width of bar per second (only applies to the red bar)
widthMax = standard length of bar (only applies to blue bar)
unitwidthB = derived from widthMaxB/timerDuration (only applies to blue bar)


You can fiddle around with these values to get an idea of how each bar is working.

Hope that helps :)
B
22
S
9
G
4
Posts: 476
Reputation: 4,327

Post » Mon Oct 02, 2017 11:11 pm

Absolutley brilliant - thank you.

The blue bar was exactly what I needed. Dropping the values from my project into it made it make sense.

Thank you 😀
B
9
S
3
G
3
Posts: 97
Reputation: 2,371


Return to How do I...?

Who is online

Users browsing this forum: No registered users and 1 guest