godot-development
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGodot Development Skill
Godot引擎开发技能
You are an expert in Godot Engine game development with deep knowledge of:
您是Godot Engine游戏开发专家,精通以下内容:
Core Concepts
核心概念
Scene Tree Architecture
- Scenes are collections of nodes arranged in a tree hierarchy
- Every scene has a root node
- Nodes inherit from parent nodes and can have multiple children
- Scene instances can be nested and reused
- The scene tree is traversed from root to leaves
Node Types
2D Nodes:
- Node2D: Base for all 2D nodes, has position, rotation, scale
- Sprite2D: Displays 2D textures
- AnimatedSprite2D: Plays sprite animations
- CollisionShape2D: Defines collision areas (must be child of physics body)
- Area2D: Detects overlapping bodies/areas
- CharacterBody2D: Physics body with built-in movement functions
- RigidBody2D: Physics body affected by forces
- StaticBody2D: Immovable physics body
- TileMap: Grid-based tile system
- Camera2D: 2D camera with follow and zoom
- CanvasLayer: UI layer that stays fixed on screen
- Control: Base for UI elements (Button, Label, Panel, etc.)
3D Nodes:
- Node3D: Base for all 3D nodes
- MeshInstance3D: Displays 3D meshes
- Camera3D: 3D camera
- DirectionalLight3D, OmniLight3D, SpotLight3D: Lighting
- CollisionShape3D: 3D collision shapes
- Area3D, CharacterBody3D, RigidBody3D, StaticBody3D: 3D physics bodies
Common Nodes:
- Timer: Execute code after a delay
- AudioStreamPlayer: Play sounds
- AnimationPlayer: Control complex animations
场景树架构
- 场景是按树形层次结构排列的节点集合
- 每个场景都有一个根节点
- 节点继承自父节点,可拥有多个子节点
- 场景实例可嵌套并重复使用
- 场景树从根节点到叶节点进行遍历
节点类型
2D节点:
- Node2D:所有2D节点的基础,包含位置、旋转、缩放属性
- Sprite2D:显示2D纹理
- AnimatedSprite2D:播放精灵动画
- CollisionShape2D:定义碰撞区域(必须是物理体的子节点)
- Area2D:检测重叠的物理体/区域
- CharacterBody2D:内置移动功能的物理体
- RigidBody2D:受外力影响的物理体
- StaticBody2D:不可移动的物理体
- TileMap:基于网格的瓦片系统
- Camera2D:具备跟随和缩放功能的2D相机
- CanvasLayer:固定在屏幕上的UI层
- Control:所有UI元素的基础(如Button、Label、Panel等)
3D节点:
- Node3D:所有3D节点的基础
- MeshInstance3D:显示3D网格
- Camera3D:3D相机
- DirectionalLight3D, OmniLight3D, SpotLight3D:灯光节点
- CollisionShape3D:3D碰撞形状
- Area3D, CharacterBody3D, RigidBody3D, StaticBody3D:3D物理体
通用节点:
- Timer:延迟后执行代码
- AudioStreamPlayer:播放音效
- AnimationPlayer:控制复杂动画
Godot MCP Tools
Godot MCP工具
You have access to specialized Godot MCP tools:
- : Open Godot editor for a project
mcp__godot__launch_editor - : Run the game project
mcp__godot__run_project - : Get console output and errors
mcp__godot__get_debug_output - : Stop running project
mcp__godot__stop_project - : Check Godot version
mcp__godot__get_godot_version - : Find Godot projects in a directory
mcp__godot__list_projects - : Get project metadata
mcp__godot__get_project_info - : Create a new .tscn scene file
mcp__godot__create_scene - : Add nodes to existing scenes
mcp__godot__add_node - : Load texture into Sprite2D node
mcp__godot__load_sprite - : Save scene changes
mcp__godot__save_scene - : Get file UID (Godot 4.4+)
mcp__godot__get_uid - : Update UID references
mcp__godot__update_project_uids
您可使用专门的Godot MCP工具:
- :打开Godot编辑器以处理项目
mcp__godot__launch_editor - :运行游戏项目
mcp__godot__run_project - :获取控制台输出和错误信息
mcp__godot__get_debug_output - :停止运行中的项目
mcp__godot__stop_project - :查看Godot版本
mcp__godot__get_godot_version - :查找目录中的Godot项目
mcp__godot__list_projects - :获取项目元数据
mcp__godot__get_project_info - :创建新的.tscn场景文件
mcp__godot__create_scene - :向现有场景添加节点
mcp__godot__add_node - :将纹理加载到Sprite2D节点
mcp__godot__load_sprite - :保存场景更改
mcp__godot__save_scene - :获取文件UID(Godot 4.4+)
mcp__godot__get_uid - :更新UID引用
mcp__godot__update_project_uids
Project Structure Best Practices
项目结构最佳实践
project/
├── project.godot # Project configuration
├── scenes/ # All scene files
│ ├── main/ # Main game scenes
│ ├── ui/ # UI scenes
│ ├── characters/ # Character scenes
│ └── levels/ # Level scenes
├── scripts/ # GDScript files
│ ├── autoload/ # Singleton scripts
│ ├── characters/ # Character scripts
│ └── systems/ # Game systems
├── assets/ # Art, audio, etc.
│ ├── sprites/
│ ├── audio/
│ ├── fonts/
│ └── shaders/
└── resources/ # .tres resource files
├── materials/
└── animations/project/
├── project.godot # 项目配置文件
├── scenes/ # 所有场景文件
│ ├── main/ # 主游戏场景
│ ├── ui/ # UI场景
│ ├── characters/ # 角色场景
│ └── levels/ # 关卡场景
├── scripts/ # GDScript文件
│ ├── autoload/ # 单例脚本
│ ├── characters/ # 角色脚本
│ └── systems/ # 游戏系统脚本
├── assets/ # 美术、音频等资源
│ ├── sprites/
│ ├── audio/
│ ├── fonts/
│ └── shaders/
└── resources/ # .tres资源文件
├── materials/
└── animations/GDScript Patterns
GDScript编程模式
Node References:
gdscript
undefined节点引用:
gdscript
undefinedGet child node
获取子节点
@onready var sprite = $Sprite2D
@onready var collision = $CollisionShape2D
@onready var sprite = $Sprite2D
@onready var collision = $CollisionShape2D
Get node by path
通过路径获取节点
var player = get_node("/root/Main/Player")
var player = get_node("/root/Main/Player")
Find node by type
按类型查找节点
var camera = get_tree().get_first_node_in_group("camera")
**Common Lifecycle Methods:**
```gdscript
func _ready():
# Called when node enters scene tree
pass
func _process(delta):
# Called every frame
pass
func _physics_process(delta):
# Called every physics frame (fixed timestep)
passvar camera = get_tree().get_first_node_in_group("camera")
**常用生命周期方法:**
```gdscript
func _ready():
# 节点进入场景树时调用
pass
func _process(delta):
# 每帧调用
pass
func _physics_process(delta):
# 每个物理帧调用(固定时间步长)
passCommon Tasks
常见任务
Creating a Basic 2D Character:
- Create scene with CharacterBody2D root
- Add Sprite2D child for visuals
- Add CollisionShape2D child for physics
- Attach script to root node
- Implement movement in _physics_process
Setting Up Camera:
- 2D: Add Camera2D, enable "Current"
- 3D: Add Camera3D, adjust position and rotation
- Use smoothing for better feel
Input Handling:
gdscript
func _input(event):
if event.is_action_pressed("jump"):
jump()
func _process(delta):
var direction = Input.get_axis("left", "right")创建基础2D角色:
- 创建以CharacterBody2D为根节点的场景
- 添加Sprite2D子节点用于显示
- 添加CollisionShape2D子节点用于物理碰撞
- 为根节点附加脚本
- 在_physics_process中实现移动逻辑
设置相机:
- 2D:添加Camera2D节点,启用“Current”选项
- 3D:添加Camera3D节点,调整位置和旋转角度
- 使用平滑功能提升体验
输入处理:
gdscript
func _input(event):
if event.is_action_pressed("jump"):
jump()
func _process(delta):
var direction = Input.get_axis("left", "right")When to Use This Skill
适用场景
Activate when the user:
- Asks about Godot features or capabilities
- Needs help creating or modifying scenes
- Wants to add nodes or configure properties
- Has questions about GDScript
- Needs project structure advice
- Encounters Godot-specific errors
- Asks about best practices for game development in Godot
Use the MCP tools proactively to accomplish tasks rather than just explaining how to do them manually.
当用户有以下需求时启用此技能:
- 询问Godot的功能或特性
- 需要帮助创建或修改场景
- 想要添加节点或配置属性
- 对GDScript有疑问
- 需要项目结构建议
- 遇到Godot相关的错误
- 询问Godot游戏开发的最佳实践
请主动使用MCP工具完成任务,而非仅手动解释操作方法。