animation instance problem
Asked Answered
D

4

0

When function gets called multiple times it only works for the last values :?
i call objective_effect_animator("concrete",column,row) with multiple column,row values but it only works for the last column,row value pair

func make_effect_2(effect,column,row,animation):
	var current=effect.instantiate()
	add_child(current)
	current.get_node("AnimationPlayer").get_animation(animation).track_set_key_value(0,0,grid_to_pixel(column,row))
	current.get_node("AnimationPlayer").get_animation(animation).track_set_key_value(0,1,Vector2(585,280))
	current.get_node("AnimationPlayer").play(animation)
	current.z_index=1
Decided answered 1/3, 2024 at 13:29 Comment(0)
W
0

Decided when are you calling this function and how?

Wendolynwendt answered 2/3, 2024 at 0:2 Comment(0)
D
0

Wendolynwendt
for i in width:
for j in height:
make_effect_2(explosion,i,j,yellow_explosion)
something like this

i think the problem is within the function maybe current gets reset can i make it instantiate it as a new variable or on a new node idk

Decided answered 2/3, 2024 at 12:47 Comment(0)
W
0

Decided Hmmmm..... I noticed the add_child() in there. That means it's always targeting the last node in the tree. So - when is this happening? Is it in process or ready or at a signal?

Wendolynwendt answered 2/3, 2024 at 19:43 Comment(0)
A
0

Decided When function gets called multiple times it only works for the last values

Are you playing different/modified animations with the same AnimationPlayer? If you try to play one of the animations before the previous one has finished, the new one will replace the previous one. If you want to play them in sequence, wait for the animation_finished signal, or use queue(animation) instead of play(animation).

I haven't used queue(animation) before, and I don't know if it would behave as expected if you're using the same value for "animation" with different track settings. In that case, it would better to wait for the animation_finished signal after each call to play(animation).

Agra answered 3/3, 2024 at 1:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.