跳到主要内容

内部函数

场景相关

get_tree()

获取全局SenceTree 例:通过 get_tree() 函数访问全局 SceneTree 对象,然后用它来重新加载并重启当前场景

func _unhandled_input(event):
if event.is_action_pressed("ui_accept") and $UserInterface/Retry.visible:
# This restarts the current scene.
get_tree().reload_current_scene()

值类型转换

  • str()
  • int()
  • float()

lerp

lerp函数是linear interpolation的缩写,即线性插值。

用于计算并返回两个值的加权平均值

下面的例子是控制元素的位置,使其跟随鼠标移动。

func _process(delta):
position = lerp(position, get_local_mouse_position(), 2.0 * delta)