godot-platform-desktop

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Platform: Desktop

平台:桌面端

Settings flexibility, window management, and kb/mouse precision define desktop gaming.
设置灵活性、窗口管理以及键鼠操作精度是桌面端游戏的核心特性。

Available Scripts

可用脚本

desktop_integration_manager.gd

desktop_integration_manager.gd

Expert desktop integration (Steam achievements, settings persistence, window management).
专业的桌面端集成功能(Steam成就、设置持久化、窗口管理)。

NEVER Do in Desktop Development

桌面端开发绝对禁忌

  • NEVER hardcode resolution/fullscreen — 1920x1080 fullscreen on 4K monitor? Blurry mess. ALWAYS provide settings menu with resolution dropdown + fullscreen toggle.
  • NEVER save settings to
    res://
    res://
    is read-only in exported builds. Use
    user://settings.cfg
    for persistent config via ConfigFile.
  • NEVER ignore Alt+F4 or Cmd+Q — Player presses Alt+F4, nothing happens = frustration. Handle
    NOTIFICATION_WM_CLOSE_REQUEST
    to quit gracefully.
  • NEVER lock rebinding — Fixed WASD movement ignores AZERTY/Dvorak keyboards. MUST allow InputMap rebinding via settings.
  • NEVER use
    linear_to_db()
    wrong
    — Volume slider 0-1 directly to AudioServer? Perceptually wrong curve. Use
    AudioServer.set_bus_volume_db(0, linear_to_db(slider.value))
    .
  • NEVER skip borderless fullscreen option — Exclusive fullscreen breaks Alt+Tab on Windows. Offer
    WINDOW_MODE_EXCLUSIVE_FULLSCREEN
    +
    WINDOW_MODE_FULLSCREEN
    (borderless).

gdscript
undefined
  • 绝对不要硬编码分辨率/全屏设置 —— 在4K显示器上强制1920x1080全屏?画面会模糊不堪。务必提供包含分辨率下拉菜单和全屏切换按钮的设置界面。
  • 绝对不要将设置保存到
    res://
    目录
    —— 导出后的构建包中
    res://
    是只读的。请使用
    user://settings.cfg
    通过ConfigFile实现配置持久化。
  • 绝对不要忽略Alt+F4或Cmd+Q快捷键 —— 玩家按下Alt+F4却毫无反应?这会引发不满。请处理
    NOTIFICATION_WM_CLOSE_REQUEST
    事件以实现优雅退出。
  • 绝对不要锁定按键绑定 —— 固定的WASD移动方式无法适配AZERTY/Dvorak键盘。必须允许通过设置界面修改InputMap的按键绑定。
  • 绝对不要错误使用
    linear_to_db()
    —— 将音量滑块的0-1值直接传给AudioServer?这不符合人类的听觉感知曲线。请使用
    AudioServer.set_bus_volume_db(0, linear_to_db(slider.value))
  • 绝对不要跳过无边框全屏选项 —— 独占全屏模式会导致Windows系统下Alt+Tab失效。请同时提供
    WINDOW_MODE_EXCLUSIVE_FULLSCREEN
    (独占全屏)和
    WINDOW_MODE_FULLSCREEN
    (无边框全屏)选项。

gdscript
undefined

settings.gd

settings.gd

extends Control
func _ready() -> void: load_settings() apply_settings()
func load_settings() -> void: var config := ConfigFile.new() config.load("user://settings.cfg")
$Graphics/ResolutionDropdown.selected = config.get_value("graphics", "resolution", 0)
$Graphics/FullscreenCheck.button_pressed = config.get_value("graphics", "fullscreen", false)
$Audio/MasterSlider.value = config.get_value("audio", "master_volume", 1.0)
func save_settings() -> void: var config := ConfigFile.new() config.set_value("graphics", "resolution", $Graphics/ResolutionDropdown.selected) config.set_value("graphics", "fullscreen", $Graphics/FullscreenCheck.button_pressed) config.set_value("audio", "master_volume", $Audio/MasterSlider.value) config.save("user://settings.cfg")
func apply_settings() -> void: # Resolution var resolutions := [Vector2i(1920, 1080), Vector2i(2560, 1440), Vector2i(3840, 2160)] var resolution := resolutions[$Graphics/ResolutionDropdown.selected] get_window().size = resolution
# Fullscreen
if $Graphics/FullscreenCheck.button_pressed:
    DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
else:
    DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)

# Audio
AudioServer.set_bus_volume_db(0, linear_to_db($Audio/MasterSlider.value))
undefined
extends Control
func _ready() -> void: load_settings() apply_settings()
func load_settings() -> void: var config := ConfigFile.new() config.load("user://settings.cfg")
$Graphics/ResolutionDropdown.selected = config.get_value("graphics", "resolution", 0)
$Graphics/FullscreenCheck.button_pressed = config.get_value("graphics", "fullscreen", false)
$Audio/MasterSlider.value = config.get_value("audio", "master_volume", 1.0)
func save_settings() -> void: var config := ConfigFile.new() config.set_value("graphics", "resolution", $Graphics/ResolutionDropdown.selected) config.set_value("graphics", "fullscreen", $Graphics/FullscreenCheck.button_pressed) config.set_value("audio", "master_volume", $Audio/MasterSlider.value) config.save("user://settings.cfg")
func apply_settings() -> void: # Resolution var resolutions := [Vector2i(1920, 1080), Vector2i(2560, 1440), Vector2i(3840, 2160)] var resolution := resolutions[$Graphics/ResolutionDropdown.selected] get_window().size = resolution
# Fullscreen
if $Graphics/FullscreenCheck.button_pressed:
    DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
else:
    DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)

# Audio
AudioServer.set_bus_volume_db(0, linear_to_db($Audio/MasterSlider.value))
undefined

Keyboard Remapping

键盘绑定重映射

gdscript
undefined
gdscript
undefined

Allow players to rebind keys

Allow players to rebind keys

func rebind_action(action: String, new_key: Key) -> void: # Remove existing InputMap.action_erase_events(action)
# Add new
var event := InputEventKey.new()
event.keycode = new_key
InputMap.action_add_event(action, event)

# Save
save_input_map()
undefined
func rebind_action(action: String, new_key: Key) -> void: # Remove existing InputMap.action_erase_events(action)
# Add new
var event := InputEventKey.new()
event.keycode = new_key
InputMap.action_add_event(action, event)

# Save
save_input_map()
undefined

Window Management

窗口管理

gdscript
undefined
gdscript
undefined

Toggle fullscreen

Toggle fullscreen

func toggle_fullscreen() -> void: if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) else: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
undefined
func toggle_fullscreen() -> void: if DisplayServer.window_get_mode() == DisplayServer.WINDOW_MODE_FULLSCREEN: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) else: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
undefined

Steam Integration (if using)

Steam Integration (if using)

gdscript
undefined
gdscript
undefined

Using GodotSteam plugin

Using GodotSteam plugin

var steam_id: int
func _ready() -> void: if Steam.isSteamRunning(): steam_id = Steam.getSteamID() Steam.achievement_progress.connect(_on_achievement_progress)
func unlock_achievement(name: String) -> void: Steam.setAchievement(name) Steam.storeStats()
undefined
var steam_id: int
func _ready() -> void: if Steam.isSteamRunning(): steam_id = Steam.getSteamID() Steam.achievement_progress.connect(_on_achievement_progress)
func unlock_achievement(name: String) -> void: Steam.setAchievement(name) Steam.storeStats()
undefined

Best Practices

最佳实践

  1. Settings - Extensive graphics/audio options
  2. Keybinds - Allow remapping
  3. Alt+F4 - Support quit shortcuts
  4. Save Location - Use
    user://
    directory
  1. 设置 - 提供丰富的图形/音频选项
  2. 按键绑定 - 允许用户重映射
  3. Alt+F4支持 - 适配退出快捷键
  4. 保存路径 - 使用
    user://
    目录

Reference

参考

  • Related:
    godot-export-builds
    ,
    godot-save-load-systems
  • 相关内容:
    godot-export-builds
    ,
    godot-save-load-systems

Related

相关

  • Master Skill: godot-master
  • 核心技能:godot-master