mcpField
G
godot-gdscript-patterns

godot-gdscript-patterns

github.com/wshobson开发41.9k17.7k 次安装2 周前更新
代码仓库

关于 godot-gdscript-patterns

面向 Godot 4.x 游戏开发的 GDScript 参考技能,涉及架构、信号、场景、状态管理与性能,并将详细示例放在单独的参考文件中。

主要功能

  1. 01Godot 4.x 架构模式
  2. 02GDScript 开发指导
  3. 03信号与场景设计
  4. 04游戏状态管理
  5. 05性能优化

适用场景

  1. 01使用 Godot 4 开发游戏
  2. 02实现 GDScript 游戏系统
  3. 03设计可复用的场景结构
  4. 04提升 GDScript 性能

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/wshobson/agents --skill godot-gdscript-patterns

安装后在 Claude Code 中输入/godot-gdscript-patterns确认已加载。

附带文件references/advanced-patterns.mdreferences/details.md

详细介绍

Godot GDScript 模式

使用 GDScript 进行 Godot 4.x 游戏开发的生产级模式,涵盖架构、信号、场景和优化。

何时使用此技能

  • 使用 Godot 4 构建游戏
  • 使用 GDScript 实现游戏系统
  • 设计场景架构
  • 管理游戏状态
  • 优化 GDScript 性能
  • 学习 Godot 最佳实践

核心概念

1. Godot 架构
Node: Base building block
├── Scene: Reusable node tree (saved as .tscn)
├── Resource: Data container (saved as .tres)
├── Signal: Event communication
└── Group: Node categorization
2. GDScript 基础
class_name Player
extends CharacterBody2D

# Signals
signal health_changed(new_health: int)
signal died

# Exports (Inspector-editable)
@export var speed: float = 200.0
@export var max_health: int = 100
@export_range(0, 1) var damage_reduction: float = 0.0
@export_group("Combat")
@export var attack_damage: int = 10
@export var attack_cooldown: float = 0.5

# Onready (initialized when ready)
@onready var sprite: Sprite2D = $Sprite2D
@onready var animation: AnimationPlayer = $AnimationPlayer
@onready var hitbox: Area2D = $Hitbox

# Private variables (convention: underscore prefix)
var _health: int
var _can_attack: bool = true

func _ready() -> void:
    _health = max_health

func _physics_process(delta: float) -> void:
    var direction := Input.get_vector("left", "right", "up", "down")
    velocity = direction * speed
    move_and_slide()

func take_damage(amount: int) -> void:
    var actual_damage := int(amount * (1.0 - damage_reduction))
    _health = max(_health - actual_damage, 0)
    health_changed.emit(_health)

    if _health <= 0:
        died.emit()

详细模式与完整示例

详细的模式文档位于 references/details.md。当上述导航层级不够用时,请阅读该文件。

评论

支持 Markdown