Godot Version
4.2.2
Question
I’m currently trying to make a score counter that goes up gradually (every 0.1 seconds). But the issue is that the numbers of the digits don’t go up separately, but instead all together. I turned on Local to Scene for the numbers in the editor, but that didn’t solve the issue.
Relevant code
Code for the number counter (changes the sprite up depending on the number):
extends Node
@export var w_size = 90
@export var h_size = 120
@onready var texture_rect = $MarginContainer/TextureRect
signal counting_finished
func number_roll(new_number : int):
for i in range(new_number + 1):
var timer = get_tree().create_timer(0.1)
await timer.timeout
change_number(i)
counting_finished.emit()
func change_number(number : int):
if number >= 10:
number = number % 10
texture_rect.texture.set_region(Rect2(w_size * number, 0, w_size, h_size))
Code controlling the number display (the numbers are instances of the same scene):
i = 1
for key in sorted_dictionary:
var container = $VBoxContainer.get_child(i).get_child(1)
print(sorted_dictionary[key] % 10, int(sorted_dictionary[key] / 10))
container.get_child(1).number_roll(sorted_dictionary[key] % 10)
await container.get_child(1).counting_finished
container.get_child(0).number_roll(int(sorted_dictionary[key] / 10))
i += 1
Would be grateful for any help!