更改 Windows 的应用程序图标

默认情况下,导出项目的图标将是 Godot 图标。你很可能想要为你的项目更改它。在 Windows 上可以更改两种类型的图标:文件图标和任务栏图标。

Creating a custom ICO file

备注

Since Godot 4.1, Godot can create an ICO file for you based on the icon file defined in the Windows export preset. This icon file can be in PNG, WebP or SVG format. If no icon is defined in the Windows export preset, the application/config/icon project setting is used automatically instead.

This means you no longer need to follow the steps in this section to manually create an ICO file, unless you wish to have control over the icon design depending on its displayed size. Note that even if Godot creates the ICO file for you, you still need to set up rcedit so that the file icon actually changes.

Windows does not use formats such as PNG or JPEG for application icons. Instead, it uses a Windows-only format called ICO. You can create your application icon in any program but you will have to convert it to an ICO file using a program such as GIMP.

这个视频教程展示了怎么用 GIMP 导出 ICO 文件。

也可以使用这个 ImageMagick 命令,将 PNG 图像转换为 hiDPI 友好的 ICO 文件:

magick convert icon.png -define icon:auto-resize=256,128,64,48,32,16 icon.ico

根据你所安装的 ImageMagick 的版本的不同,你可能会需要把 magick 去掉,运行以下命令:

convert icon.png -define icon:auto-resize=256,128,64,48,32,16 icon.ico

警告

为了使 ICO 文件有效地替换默认 Godot 图标,它必须包含默认 Godot 图标所包含的所有尺寸:16×16、32×32、48×48、64×64、128×128、256×256。如果该 ICO 文件未包含所有尺寸,没有被覆盖的尺寸将保留默认 Godot 图标。

上面的 ImageMagick 命令考虑到了这一点。

更改任务栏图标

任务栏图标是项目运行时显示在任务栏上的图标。

../../_images/icon_taskbar_icon.png

To change the taskbar icon, go to Project > Project Settings > Application > Config, make sure Advanced Settings are enabled to see the setting, then go to Windows Native Icon. Click on the folder icon and select your ICO file.

../../_images/icon_project_settings.webp

这个设置只会修改 Windows 导出的游戏图标。设置 macOS 的图标请使用 Macos Native Icon(macOS 原生图标)。其他平台请使用 Icon(图标)设置。

更改文件图标

从 Godot 3.5 开始,你可以使用 godoticon 来修改文件图标,无需外部工具。使用这种方法修改图标应该对内嵌 PCK 的可执行文件也有效。

文件图标是你单击以启动游戏的可执行文件的图标。

../../_images/icon_file_icon.png

在导出选项中选择它之前,你需要额外安装一个名为 rcedit 的工具。你可以在这里进行下载。

After downloading, you need to tell Godot the path to the rcedit executable on your computer. Go to Editor > Editor Settings > Export > Windows. Click on the folder icon for the rcedit entry. Navigate to and select the rcedit executable.

备注

Linux 和 macOS 用户还需要安装 WINE 才能使用 rcedit。

On macOS, make sure to use a 64-bit version of both WINE and rcedit since 32-bit applications aren't supported anymore.

../../_images/icon_rcedit.webp

You should now have everything in place to change the file icon. To do that, you will need to specify the icon when exporting. Go to Project > Export. Assuming you have already created a Windows Desktop preset, select your icon in ICO format in the Application > Icon field.

警告

所有提供的元数据都必须有效。最重要的是,版本标识符必须采用 主版本.次版本.补丁版本.修订版本 的形式,其中每个部分都必填、必须是正整数。例如,1.2.0.0 有效,而 1.2.0 无效。

如果你在导出预设中提供无效元资料,应用程序图标将不会更改,因为rcedit将无法更改可执行档案的元资料。

../../_images/icon_export_settings.webp

备注

如果 rcedit 修改图标失败,你可以在改变图标后编译你自己的 Windows 导出模板。实现方法是在编译导出模板之前用你自己的 ICO 文件替换 platform/windows/godot.ico

这样做之后,你就可以在项目的 Windows 导出预设中将你的导出模板指定为自定义导出模板。

测试结果

你现在可以导出项目了。如果一切正常,你应该看到:

../../_images/icon_result.png

备注

如果你的图标没有正确显示,在 Windows 10 中,请尝试清理图标缓存。实现方法是打开运行对话框并输入 ie4uinit.exe -ClearIconCacheie4uinit.exe -show