Godot Version
4.3
Question
New to Godot and I’m stuck trying to adapt my game so that it works across all types of Android devices. Low-end devices have been been source of great, great, colossal pain. I want to display to the player a simple timer: minutes and seconds.
The player is challenged to do certain things within a certain amount of time, so to see the timer being jumpy/inaccurate would lead to a poor experience for players.
Attempt #1:
I added a simple 1 second timer, some simplified code like so:
Timer.start()
func timer_end():
time += 1
%clock.text = displayTimeAsText(time)
Timer.start()
Easy enough I thought, but when testing the time was all over the place. After 1 minute it was off by 6 seconds in one test and 13 seconds in another.
Attempt #2:
var time_elapsed:float = 0.0
var counter:int = 1
func _process(delta):
time_elapsed += delta
if floor(time_elapsed) == counter:
%clock.text = displayTimeAsText(counter)
counter += 1
Improved, but timing was still off. Attempt #3 was to try this on the _physics_process(delta) but I had the same results.
Attempt #4:
var time_elapsed:float = 0.0
var counter:int = 1000
var start_time:int
func start_game():
start_time = Time.get_ticks_msec()
func _process(delta):
time_millisec = Time.get_ticks_msec() - startTime
if floor(time_millisec) >= counter:
counter += 1000
%clock.text = displayTimeAsText(counter/1000)
After 1 minute, attempt #4 gave me the most accurate results, but the clock was jumping, the count up was noooooot smooth at all. And with all my testing, I wasn’t even playing the game. I was just starting the game and letting the clock go. With no other activities the clock still was jumpy, so my fear is that during game play with more going on the clocks performance would only get worse on these low-tier devices.
Am I missing something basic here? And words would be helpful. Thanks.