如何将godot3项目转为godot4

  • onready修改为@onready
  • export修改为@export
# 如果变量后面是 := 那么就需要定义get或者set,如果是 = 就不需要定义
@export var detail := 0  :
	set = set_tileset
    get = get_tileset
  • 枚举值修改为@export_enum(...) var v: String = ""
  • tween节点使用create_tween()进行创建
  • yield改为await
  • 信号的连接改为signala.connect(funca)
  • 时间的获取
# 修改前
var d = OS.get_datetime()
d.erase("dst")
var s = ""

for i in (d.values()):
    s += str(i) + " "

# 修改后
var time = Time.get_datetime_dict_from_system()
time.erase("dst") # 删除夏令时标志

var datetime_string := ""
for value in time.values():
    datetime_string += str(value) + " "

print(datetime_string)
  • Engine相关

# 修改前
func set_iterations(arg := iterations):
	iterations = max(1, arg)
	Engine.iterations_per_second = iterations

func set_target_fps(arg := target_fps):
	target_fps = abs(arg)
	#print("target_fps: ", target_fps)
	Engine.target_fps = target_fps
    
# 修改后
func set_iterations(arg := iterations):
    iterations = max(1, arg)
    ProjectSettings.set_setting("physics/iterations_per_second", iterations)

func set_target_fps(arg := target_fps):
    target_fps = abs(arg)
    ProjectSettings.set_setting("display/window/target_fps", target_fps)
  • MainLoop.NOTIFICATION_WM_QUIT_REQUEST修改为``
  • 文件操作相关, File修改为FileAccess, Dir修改为DirAccess
  • PoolVector2Array修改为PackedVector2Array
  • update()修改为queue_redraw()方法,重新绘制
  • deg2rad修改为deg_to_rad
  • color.white修改修改为color.WHITE,所有颜色名称都变成大写了
  • extends VisibilityNotifier2D修改为extends VisibleOnScreenNotifier2D
  • Engine.editor_hint修改为Engine.is_editor_hint()
  • KinematicBody2D修改为CharacterBody2D
  • Sprite修改为Sprite2D
  • stepify修改为snapped
  • InputMap.get_action_list修改为InputMap.action_get_events
  • set_shader_param修改为set_shader_parameter