It feels kind of stupid to ask, but I can’t figure it out.
How do I make a sort of score counter, which animates the score from 0 to the final score in a game over screen?
Something along the lines of the example below, from Bore Blasters:
I tried doing this with a tween, ‘animating’ the score. I tried it with a lerp function. But both tries didn’t work. I’m thinking I could try it with a timer and every time it goes off, add something to the score.
But there has to be a simple way that I have overlooked.
When I search for this on Youtube or something, I only get results on how to add score by using a global variable and showing this on screen with a label. But I know how to do that. I want it to animate/count up.
var time
var time_to_current_score : float
var a = true
func _process(delta):
if finished and a:
time += delta
text = time / time_to_current_score * score
if time >= time_to_current_score:
a = false
Thank you very much! This is exactly what I was after, including the option to set the amount of time the counting should take.
I modified it a bit, so at the end it shows the score, instead of the result of the calculation, which overshoots the score a bit. And the counting shows as an integer now.
Thanks again! You have no idea how much I’ve thought about how to do this.
var finished = true
var time = 0.0
var time_to_current_score = 2.0
var a = true
var score = 1001
func _process(delta):
if finished and a:
time += delta
text = str(int(time / time_to_current_score * score))
if time >= time_to_current_score:
a = false
text = str(score)