# 输入映射配置指南 本文档说明了WhaleTown项目的输入映射配置要求和设置方法。 ## 🎮 必需的输入映射 ### 基础移动控制 - **`move_left`** - 向左移动 - 推荐按键:A键、左方向键 - **`move_right`** - 向右移动 - 推荐按键:D键、右方向键 - **`move_up`** - 向上移动 - 推荐按键:W键、上方向键 - **`move_down`** - 向下移动 - 推荐按键:S键、下方向键 ### 交互控制 - **`interact`** - 交互动作 - 推荐按键:E键、空格键 - **`pause`** - 暂停游戏 - 推荐按键:ESC键 ## ⚙️ Godot编辑器配置步骤 ### 1. 打开输入映射设置 1. 在Godot编辑器中打开 `Project` → `Project Settings` 2. 切换到 `Input Map` 标签 ### 2. 添加输入动作 对于每个必需的输入动作: 1. 在 `Action` 输入框中输入动作名称(如 `move_left`) 2. 点击 `Add` 按钮 3. 点击新添加动作右侧的 `+` 按钮 4. 按下对应的按键进行绑定 5. 重复步骤3-4添加备用按键 ### 3. 配置示例 ``` move_left: - Key: A - Key: Left Arrow move_right: - Key: D - Key: Right Arrow move_up: - Key: W - Key: Up Arrow move_down: - Key: S - Key: Down Arrow interact: - Key: E - Key: Space pause: - Key: Escape ``` ## 🔧 代码中的使用方法 ### 移动输入检测 ```gdscript func _physics_process(delta: float) -> void: # 获取移动向量 var direction := Input.get_vector( "move_left", "move_right", "move_up", "move_down" ) # 应用移动 velocity = direction * move_speed move_and_slide() ``` ### 交互输入检测 ```gdscript func _input(event: InputEvent) -> void: if event.is_action_pressed("interact"): _handle_interaction() if event.is_action_pressed("pause"): _toggle_pause() ``` ### 连续输入检测 ```gdscript func _process(delta: float) -> void: # 检测持续按下的按键 if Input.is_action_pressed("interact"): _continuous_interaction(delta) ``` ## 📱 手柄支持(可选) ### 推荐手柄映射 - **左摇杆** - 移动控制 - **A按钮/X按钮** - 交互 - **Start按钮** - 暂停 ### 配置方法 1. 在Input Map中为每个动作添加手柄输入 2. 使用 `Joypad Button` 或 `Joypad Axis` 进行绑定 ## ✅ 验证配置 ### 测试脚本 创建一个简单的测试脚本验证输入配置: ```gdscript extends Node func _ready() -> void: print("输入映射测试开始...") _test_input_actions() func _test_input_actions() -> void: var required_actions = [ "move_left", "move_right", "move_up", "move_down", "interact", "pause" ] for action in required_actions: if InputMap.has_action(action): print("✅ ", action, " - 已配置") else: print("❌ ", action, " - 未配置") func _input(event: InputEvent) -> void: # 实时显示输入事件 for action in InputMap.get_actions(): if event.is_action_pressed(action): print("按下: ", action) ``` ## 🚨 常见问题 ### Q: 输入没有响应怎么办? A: 检查以下几点: 1. 确认输入动作名称拼写正确 2. 验证按键是否正确绑定 3. 检查代码中是否正确使用了动作名称 ### Q: 如何添加自定义输入? A: 按照相同步骤在Input Map中添加新的动作,并在代码中使用对应的动作名称。 ### Q: 手柄不工作怎么办? A: 确保手柄已连接,并在Input Map中正确配置了手柄按钮映射。 --- **注意:输入映射配置是游戏正常运行的基础,请确保所有必需的输入动作都已正确配置!**