Use timer to change progress bar value
Asked Answered
R

5

0

Hello!

I am using the timer to change the progress bar value inside the process function:
func _physics_process(_delta: float) → void:
progress_bar.value = timer.wait_time - timer.time_left

My question is, is there another way to do this? Because the timer only has the timeout signal.

Sorry, if this question is not a valid question, or it has been answered before.

Riffe answered 17/9, 2023 at 3:0 Comment(0)
K
0

Riffe What's wrong with doing it this way?

Kulsrud answered 17/9, 2023 at 3:3 Comment(0)
R
0

Kulsrud I really do not know. I am just wondering if there are other methods to do this, just to learn them or understand it, I am new to Godot.

Riffe answered 17/9, 2023 at 3:6 Comment(0)
K
0

Riffe You can use a tween to directly animate the value property, avoiding the timer altogether.

Kulsrud answered 17/9, 2023 at 3:10 Comment(0)
G
0

you could do it how ive been doing it, its not the most elegant way and personally I like yours better

I set four variables 1 of which is just a reference to the progress bar
@onready var progressBar: ProgressBar = $ProgressBar
signal progress_completed
var progressLength: float = 0.0
var currentProgress: float = 0.0

func _ready() -> void:
progressBar.max_value = progressLength
progressBar.value = 0.0

func _process(delta : float) -> void:
if currentProgress < progressLength:
currentProgress += delta
progressBar.value = currentProgress
else:
emit_signal("progress_completed")

this is a much less elegant way to do what your doing but it does allow for custom signals also you could just use a timer timeout signal to trigger your custom signal to do what you want.

hope this helps and isn't just garbage

Gracielagracile answered 17/9, 2023 at 8:2 Comment(0)
O
0

Kulsrud I agree that tweens would be the best for something like that. Almost no need for addiotional custom code and you have much more control over value change. You can use different easing and if you need you can chain callbacks etc.

Ondometer answered 17/9, 2023 at 9:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.