0 votes

Good day,

I want to make a progress bar, which countsdown time (eg: 15-20 seconds), and as the player hits milestones, the time increases in the bar. How can i achieve this using progress bar. Please help, or suggest your way. Thanks a ton.

in Engine by (73 points)

1 Answer

+1 vote

Perhaps something like this?

extends ProgressBar

var timer = Timer.new()

export (float, 0.0, 100.0, .1) var start_time = 15.0
export (float, 0.0, 100.0, .1) var end_time   = 20.0

func _ready():

    timer.set_timer_process_mode(Timer.TIMER_PROCESS_FIXED)
    timer.set_wait_time(end_time - start_time)
    timer.set_one_shot(true)
    timer.connect("timeout", self, "gameover")

    add_child(timer)
    timer.start()

    set_fixed_process(true)

func gameover():
    print("GAME OVER - TIME RAN OUT")
    set_fixed_process(false)

var t = 1

func _fixed_process(delta): # Print testing

    if(t >= 1):
        t -= 1
        print(timer.get_time_left())

    t += delta

const ADDITIONAL_TIME = 3.0

func _on_Button_pressed(): # Button for testing

    # Must get time before stopping timer.
    var new_time = timer.get_time_left() + ADDITIONAL_TIME

    timer.stop()
    timer.set_wait_time(new_time)
    timer.start()
by (5,192 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.