extends Path2D
var time
func _ready():
curve.add_point(Vector2(0,0),Vector2(0,-100),Vector2(0, -100),0) #起始点
pass
func _process(delta):
if Input.is_action_just_pressed("ui_accept"):#按下空格监听,打开计时器,要改变Timer的默认值
print("start")
get_node("PathFollow2D/Sprite2D/Timer").start()
if Input.is_action_just_released("ui_accept"):
time=get_node("PathFollow2D/Sprite2D/Timer").wait_time-get_node("PathFollow2D/Sprite2D/Timer").time_left #获得按空格时间
curve.add_point(curve.get_point_position(0)+Vector2(time*400,0),Vector2(0, -time*400),Vector2(0, -time*400),1)#设置落点
print(time)
get_node("PathFollow2D").progress_ratio=0#准备开始偏移
if get_node("PathFollow2D").progress_ratio!=1 :
if get_node("PathFollow2D").progress_ratio<=0.3:
get_node("PathFollow2D").progress_ratio+=0.02
else:
get_node("PathFollow2D").progress_ratio+=0.01
else:
curve.remove_point(0) #删除起始点确保不回到原点
pass
节点设置如下图: