Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | karg |
So i have this code who loop thru my 2 instanced scene(wich is one scene instanced twice so 2 identical instance) . I have an animation player in a sprite showing the result of the variable ion a 5 stars rating so 50= 2.5 stars and 100 = 5 stars. But the 2 animation are always showing the same result wich is the last instance going thru the loop( resulting in 50 so showing 2.5 stars)
CODE:
extends Node
export var categorie_scores : Dictionary = {
"efficiency": 100,
"durability": 50
}
#Function
func _ready():
var i = 0
for category in categorie_scores.keys():
var progress : Node = self.get_child(i)
var score : int = categorie_scores[category]
var _succ = progress.setCoeff(score)
progress.startAnimation()
print("%s -> %s : %d" % [progress.name, category, score])
i += 1
i tried to debug but everything seems to work fine…
Here is what the print shows in the console:
5
FiveStarProgress -> efficiency : 100
2.5
FiveStarProgress2 -> durability : 50
So my question i guess is how can i make two identical instance work . ive tried with the instance() function two and same result( with a different code than this one of course ) the 2 animations are always showing the same result instead of showing the 2 result it should be.
Thanks a lot in advancefor the help!
startAnimation function and SetCoeff Function:
extends Sprite
#var
var coeff
var duration : float = -1
var number_anim_playing : int = 1
# Called when the node enters the scene tree for the first time.
func _ready():
pass
func setCoeff(value : int) -> bool :
if value < 0 or value > 100:
print("coeff should be between 0 and 100")
return false
duration = ((value * 5) / 100.0)
return true
func startAnimation():
if duration == -1:
print("you need to set the coeff first")
return
$AnimationPlayer.play("emptyToFull", -1, 1)
$AnimationPlayer.get_animation('emptyToFull').length = duration
ps: hope the explanation is not to hard to understand
By the looks of it, you don’t seem to be passing any arguments to the startAnimation()
function. Can you post the code that drives the animation?
johnygames | 2020-08-16 22:59
Hey thanks for your comment. i edited the post to add the animation function. Hope u can help !
karg | 2020-08-16 23:17