# tilemap

> TileMap/TileMapLayer 图块操作。读取: tilemap_read, tilemap_copy。写入: tilemap_set_cell, tilemap_erase_cell, tilemap_fill_rect, tilemap_clear, tilemap_paste, tilemap_set_transform。传 scene_path 可对任意场景操作，省略则用主场景。运行时操作，仅影响当前执行上下文。如需持久化，请编辑 .tscn 文件。

| 属性 | 值 |
|------|-----|
| 所属层 | headless |
| 安全级别 | guarded |
| 需要 Godot | 是 |
| 需要编辑器 | 否 |
| 只读 | 否 |
| 长耗时 | 否 |

## Actions

- `tilemap_read`
- `tilemap_set_cell`
- `tilemap_erase_cell`
- `tilemap_fill_rect`
- `tilemap_clear`
- `tilemap_copy`
- `tilemap_paste`
- `tilemap_set_transform`

## Parameters

| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| `action` | enum (8 项) | ✓ | 操作类型 |
| `project_path` | string |  | Godot 项目目录路径（可选，默认使用 GODOT_PROJECT_PATH 环境变量或当前目录） |
| `node_path` | string |  | TileMap/TileMapLayer 节点路径（如 root/Level/TileMap）；配合 scene_path 时相对该场景解析，可省略 root/ 前缀和场景根节点名 |
| `scene_path` | string |  | 目标场景路径（相对项目路径，可选）。不传则加载 application/run/main_scene——主场景是菜单时其中不含 TileMap，会返回 TILEMAP_NOT_FOUND |
| `layer` | number |  | 图层索引（可选，默认 0）。tilemap_read/set_cell/erase_cell/fill_rect/copy/paste/set_transform 使用；tilemap_clear 不传则清除所有图层 |
| `region` | object |  | 矩形区域 Rect2i。tilemap_read: 读取区域（可选，不传则读取全部已用图块）；tilemap_fill_rect: 填充区域 |
| `source_region` | object |  | 源区域 Rect2i。tilemap_copy 使用 |
| `coords` | object |  | 图块坐标 Vector2i。tilemap_set_cell/erase_cell/set_transform 使用 |
| `source_id` | number |  | TileSet 源 ID。tilemap_set_cell/fill_rect 使用 |
| `atlas_coords` | object |  | 图集坐标 Vector2i。tilemap_set_cell/fill_rect 使用 |
| `alternative_tile` | number |  | 替代图块索引（可选，默认 0）。tilemap_set_cell/fill_rect 使用 |
| `target` | object |  | 粘贴目标坐标 Vector2i。tilemap_paste 使用 |
| `pattern` | object |  | 图块图案（由 tilemap_copy 返回的 pattern 对象）。tilemap_paste 使用 |
| `flip_h` | boolean |  | 水平翻转（可选，默认 false）。tilemap_set_transform 使用 |
| `flip_v` | boolean |  | 垂直翻转（可选，默认 false）。tilemap_set_transform 使用 |
| `transpose` | boolean |  | 转置（可选，默认 false）。tilemap_set_transform 使用 |
| `load_autoloads` | boolean |  | 是否加载 Autoload 上下文（默认 true） |

## 风险分布

读 2 / 写 5 / 破坏性 1

---
<!-- AUTO-GENERATED by scripts/gen-tool-docs.mjs from capability-matrix.json v0.32.21. DO NOT edit manually; re-run npm run gen:tool-docs after tool changes. -->
