0 votes

i would like to create a countdown timer that uses the progress bar as timer?

in Engine by (29 points)

1 Answer

+2 votes
Best answer

Create a new scene. Add two nodes, a ProgressBar and a Timer. Create a new script for the root node of the scene. Write the following code in it:

extends Node2D
onready var timer = get_node("Timer")
onready var pb = get_node("ProgressBar")

func _ready():
    timer.wait_time = pb.value

func _process(delta):
    pb.value = timer.time_left

Now your Timer uses the ProgressBar's value as its countdown time. You can even see the ProgressBar decreasing as time goes by.

In case you didn't know, you can set the ProgressBar's value by using its value method.
If this is what you want, please mark this answer as best.

by (1,861 points)
selected by
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.