1
0
mirror of https://gitee.com/freeyz/godot-mota.git synced 2024-12-23 08:39:19 +08:00
godot-mota/scripts/ArrayTween.gd
mydataway_yangzhe 7ca0be1f81 初次提交
2020-07-21 20:34:34 +08:00

49 lines
962 B
GDScript

extends Tween
class_name ArrayTween
var index = 0
var values : Array
# 单个节点动画时间
export var duration: float = 1.0
# 动画步进回调
signal array_value_step(step)
# 所有节点动画播放完成
signal array_completed
func _ready():
connect("tween_completed",self,"on_tween_completed")
pass
# 使用节点进行动画
func interpolate_array(values:Array) -> void:
if values.size() < 2:
return
if is_active():
stop_all()
self.index = 0
self.values = values
play_step()
# 播放其中一节
func play_step():
var start_value = values[index]
var end_value = values[index + 1]
self.interpolate_method(self,"on_step",start_value,end_value,duration)
self.start()
# 程序内步进回调
func on_step(step):
emit_signal("array_value_step",step)
pass
# 动画完成回调
func on_tween_completed(object: Object, key: NodePath):
if index + 2 < values.size():
index += 1
play_step()
else:
emit_signal("array_completed")