多此一举的部份,只是为了举例
extends Node
class_name ease_timer
var timer :int = 0 ## 定时秒
var timerTask
var obj
signal timer_stop
func _init(set_obj :SceneTree, set_timer :int) -> void:
timer = set_timer
obj = set_obj
func start():
timerTask = obj.create_timer(timer)
await timerTask.timeout
emit_signal("timer_stop")
return timerTask
func stop() -> void:
timerTask.free()
var my_timer = ease_timer.new(get_tree(), 10)
my_timer.start()
await my_timer.timer_stop
换一个载入方式
#const myt = preload("res://...gd")
var myt = load("res://....gd")
var my_timer = myt.new(get_tree(), 10)
my_timer.start()
await my_timer.timer_stop