Topic was automatically imported from the old Question2Answer platform.
Asked By
ZeralldGames
Привет! Я бы хотел создать таймер в моей игре. Есть ли какой то способ сделать таймер в Label? Это можно так же использовать как время,проведенное в игре. Спасибо за все ваши подсказки!
Hey! I would like to create a timer in my game. Is there some way to make a timer in the Label? This can also be used as the time spent in the game. Thanks for all your tips!
You can create timer by writing this code (sorry, it is c#):
Timer timer = new Timer();
AddChild(timer);
timer.Connect("timeout", this, "OnTimerTimeout");
timer.WaitTime = waitTime;
timer.OneShot = false;
timer.Start();
void OnTimerTimeout()
{
// there should be some code to execute when the timer expires
}
For more detailed information you can look in documentation.
Okay, thanks a lot anyway. But is there really no even simple alternative to the timer in GDScript?
var t : float = 0.0
func _physics_process(delta):
t += 1.0/60.0
print(t)
так вот _physics_process обновляется 60 раз в секунду, если прибавлять каждый
тик прибавлять 1/60, то в принципе можно сделать кривой косой, но рабочий таймер
или можно так
var t : float = 0.0
func _timer():
print(t)
t += 1.0
yield(get_tree().create_timer(1.0), 'timeout')
#in godot 4.0 await get_tree().create_timer(1.0/60.0).timeout
_timer()