Files
whale-town-front/docs/01-项目入门/输入映射配置.md
moyin 1ff677b3b2 docs: 重新组织文档结构,按开发阶段分类
新的目录结构:
  01-项目入门/     # 新人必读,项目基础
  02-开发规范/     # 编码标准和规范
  03-技术实现/     # 具体开发指导
  04-高级开发/     # 进阶开发技巧
  05-部署运维/     # 发布和部署
  06-功能模块/     # 特定功能文档

 新增导航文档:
- docs/README.md - 完整的文档导航和使用指南
- 各目录下的README.md - 分类说明和使用指导

 优化效果:
- 开发者可以按阶段快速定位需要的文档
- 新人有清晰的学习路径
- 不同角色有针对性的文档推荐
- 提供了问题导向的快速查找功能
2025-12-31 18:02:16 +08:00

157 lines
3.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 输入映射配置指南
本文档说明了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中正确配置了手柄按钮映射。
---
**注意:输入映射配置是游戏正常运行的基础,请确保所有必需的输入动作都已正确配置!**