Godot Version
4.2
Question
this is a long question:
I am implementing a feature in a dialogue system that will allow the avatar to transit facial expression fluently. I implemented it using tween and here is a fraction of the code:
var which_slot = %avatar.find_child(position).find_child(slot)
if transition == "false":
which_slot.texture = ResourceLoader.load(avatar_at)
else:
%avatar.find_child(position + "back").find_child(slot).texture = ResourceLoader.load(avatar_at)
var transit = which_slot.create_tween()
transit.tween_property(which_slot, "modulate:a", 0, 0.2)
await transit.finished
which_slot.texture = ResourceLoader.load(avatar_at)
which_slot.modulate.a = 1
What it does is find the respected texture rect under a canvas layer. Spawn the new face in a texture rect with same position and is sorted behind the texture rect. Then use tween to make the front texture rect transparent. After the front texture rect is completely transparent. replace the front texture rect with the texure in texure rect behind it.
Here is an idea of the larger part of code:
variable such as position, slot, and avatar_at are stored in an array which is stored with other arrays in json format. The arrays are passed one by one into this function. It is guaranteed that those variable works.
The above chunck of code is quite stupidly disigned but managed to work when a single avatar is needed to change. It does not when multiple avatar need to transit at the same time. where the avatar with its variable array passed in after the other will “vanish” and suddently appear. Which means the tween work but sth went funny with everything after it.
Please help me out, thanks in advance!
ps: I know that tween can be set_parallel() but that only applys for a single tween.
pss: await is necessary, at least for this stupid version of design