Visual Studio Code

Visual Studio Code is a free cross-platform code editor by Microsoft (not to be confused with Visual Studio).

导入项目

  • Make sure the C/C++ extension is installed. You can find instructions in the official documentation.

  • 现在在VS Code中打开克隆的godot文件夹**文件 > 打开文件夹...**。

  • 按Ctrl + Shift + P打开命令提示符窗口,然后输入 Configure Task

../../../_images/vscode_configure_task.png
  • 选择从模板中创建tasks.json文件选项。

../../../_images/vscode_create_tasksjson.png
  • 然后选择“其他”。

../../../_images/vscode_create_tasksjson_others.png
  • tasks.json 文件中找到 "tasks" 数组,并在其中添加一个新部分:

{
  "label": "build",
  "type": "shell",
  "command": "scons",
  "group": "build",
  "args": [
    "platform=x11", // Change to your current platform
    "target=debug",
    "-j4"
  ],
  "problemMatcher": "$msCompile"
}
../../../_images/vscode_3_tasks.json.png

填好了``tasks.json``的一个例子。

Arguments can be different based on your own setup and needs. See 构建系统介绍 for a full list of arguments.

Debugging the project

为了构建项目,我们需要配置文件 launch.json

  • 按Ctrl + Shift + D打开``运行''面板。

  • 如果缺少 launch.json 文件,系统会提示你创建一个新的文件。

../../../_images/vscode_1_create_launch.json.png
  • 选择 C++ (GDB/LLDB) 。这里可能还有其他特定平台的选项。如果选择了,请相应调整所提供的配置示例。

  • launch.json 文件中找到 "configurations" 数组,并添加一个新部分:

{
  "name": "Launch",
  "type": "cppdbg",
  "request": "launch",
  // Change the path below to match your current platform.
  "program": "${workspaceFolder}/bin/godot.x11.tools.64",
  // Change the arguments below for the project you want to test with.
  // To run the project instead of editing it, remove the "--editor" argument.
  "args": [ "--editor", "--path", "path-to-your-godot-project-folder" ],
  "stopAtEntry": false,
  "cwd": "${workspaceFolder}",
  "environment": [],
  "externalConsole": true,
  "MIMode": "gdb",
  "setupCommands": [
    {
      "description": "Enable pretty-printing for gdb",
      "text": "-enable-pretty-printing",
      "ignoreFailures": true
    }
  ],
  "preLaunchTask": "build"
}
../../../_images/vscode_2_launch.json.png

An example of a filled out launch.json.

program [程序]下的名称取决于你的构建配置,例如启用 tools 的64位X11平台 godot.x11.tools.64

如果遇到问题,也可在 Godot社区论坛 中寻求帮助。