- Sep 2, 2018
- 577
- 794
- 152
Like I said in the post, the cause of the problem was uncapped FPS, hitting 500, when making the scene at first, then seeing it act out in 60FPS - the math simply wouldn't work because it wasn't being called 500 times per second, only 60. To make it clearer, the function looked something like this:Hmm, have you tried creating a timer that randomizes itself every time it ends, so the "if" checks won't be called at the same frame every time? I did that for a "fire damage" timer in my godot game, and it helped not only the performance, but also made competing sounds not play at the same time. Not sure, but maybe it could help you
View attachment 5409379
Like this: timer node's timeout signal randomizes its time, you can make it as random as you want that way, works for any timer that won't need to be 100% precise.
Python:
var elapsedtime:float = 0
var fadein:float = 1
func _process(delta:float) -> void:
elapsedtime += delta
if elapsedtime > 1 and fadein > 0:
fadein -= 0.002
$blackrectangle.color = Color(0,0,0,fadein)
Lastly, I do need precision with the time when something starts and ends in this case, since it's animation, so AnimationPlayer was the best choice for this. I did consider using Tween, but dealing with time elapsed in code, then adding a flag to not run the tween a second time would be more work.