cocos2d-cli/SKILL.md
Cocos Creator 2.4.x 场景/预制体命令行工具,支持读写 .fire/.prefab、JSON 生成 UI、截图预览
npx skillsauth add 958877748/skills cocos2d-cliInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Cocos Creator 2.4.x 场景/预制体命令行工具。
AI 通过此技能可以直接读写 .fire 和 .prefab 文件,支持从简化 JSON 或 HTML 生成场景/预制体,以及通过截图预览 UI 结构。
# 1. 查看帮助
cd <项目目录>
node scripts/tree.js --help
# 2. 查看节点树
node scripts/tree.js assets/main.fire
# 3. 创建预制体
node scripts/create-prefab.js panel.json assets/Panel.prefab
# 4. 截图预览
node scripts/screenshot.js panel.json -o ./screenshots --width 750 --height 1334
node scripts/tree.js <场景.fire | 预制体.prefab>
输出 JSON 格式的节点树结构,包含节点名、子节点、组件列表。
注意:
{"name":"Canvas","children":[...],"components":[...]}build 命令生成的映射node scripts/get.js <文件> <节点路径> [属性名|组件类型]
节点路径格式:Canvas、Canvas/MidNode、Canvas/GameScene/NodeA
node scripts/set.js <文件> <节点路径> <属性名> <值>
支持属性:name, active, x, y, width, height, anchorX, anchorY, opacity, scaleX, scaleY, rotation
node scripts/set-component.js <文件> <节点路径> <组件类型> <属性名> <值>
示例:
node scripts/set-component.js assets/main.fire Canvas/Label Label string "Hello"
node scripts/add.js <文件> <父节点路径> <节点名称> [选项]
选项:--x=, --y=, --width=, --height=, --scaleX=, --scaleY=, --rotation=, --active=, --type=sprite|label|button, --string=, --fontSize=
node scripts/remove.js <文件> <节点路径>
node scripts/add-component.js <文件> <节点路径> <类型>
node scripts/remove-component.js <文件> <节点路径> <类型>
node scripts/start-scene.js [项目路径]
输出格式:db:assets/scene/main.fire
node scripts/build.js <Cocos项目目录>
扫描 library/imports,构建脚本哈希到类名的映射。在读取自定义脚本组件前需要先执行。
# 从 JSON 创建
node scripts/create-prefab.js <json文件路径> <输出.prefab>
# 从 HTML 创建
node scripts/create-prefab.js <html文件路径> <输出.prefab>
node scripts/create-scene.js [JSON文件路径] <输出.fire>
不传 JSON 时创建默认场景(含 Canvas + Main Camera)。
node scripts/screenshot.js <json文件> [选项]
选项:
| 参数 | 说明 | 默认值 |
|------|------|--------|
| -o, --output <目录> | 输出目录 | 当前目录 |
| --width <数值> | 视口宽度 | 750 |
| --height <数值> | 视口高度 | 1334 |
| --full-page | 全页截图 | 启用 |
| --no-full-page | 仅视口截图 | - |
| --debug-bounds | 叠加节点边界和名称 | - |
| --timeout <毫秒> | 截图超时 | 30000 |
| --wait <毫秒> | 渲染后等待 | 1000 |
注意:依赖 Playwright。首次使用需安装:npx playwright install chromium
{
"name": "Panel",
"width": 400,
"height": 300,
"x": 0,
"y": 0,
"anchorX": 0.5,
"anchorY": 0.5,
"color": "#336699",
"opacity": 255,
"components": [
"sprite",
{ "type": "label", "string": "Hello", "fontSize": 28 }
],
"children": [
{
"name": "Btn",
"width": 200,
"height": 60,
"components": ["sprite", "button"]
}
]
}
name, x, y, width, height, anchorX, anchorY, scaleX, scaleY, rotation, opacity, active, color(十六进制), components, children
| 组件名 | 关键配置 |
|--------|----------|
| canvas | - |
| sprite | - |
| label | string, fontSize, lineHeight, horizontalAlign (left/center/right), verticalAlign, color |
| button | - |
| widget | isAlignLeft/Right/Top/Bottom, left/right/top/bottom |
| richText | string, fontSize, lineHeight, maxWidth, horizontalAlign |
| camera | - |
Cocos Creator 默认锚点在节点中心(anchorX=0.5, anchorY=0.5),x/y 是相对父节点中心点的偏移。
左对齐推荐:
{ "anchorX": 0, "horizontalAlign": "left" }
右对齐推荐:
{ "anchorX": 1, "horizontalAlign": "right" }
Canvas # 根节点
Canvas/MidNode # 二级节点
Canvas/GameScene/NodeA # 三级节点
执行任何操作前,工具会自动从文件路径向上查找 Cocos 项目根目录:
.fire / .prefab 文件所在目录开始向上查找assets/ 和 settings/project.json 的目录,即为项目根data/script_map.json、library/imports/ 等项目级文件所以传文件路径时,给相对路径或绝对路径都可以——工具会自动找到项目根。
# 以下两种写法都能正确找到项目根
node scripts/tree.js assets/main.fire
node scripts/tree.js C:/Projects/MyGame/assets/ui/panel.prefab
npx playwright install chromiumassets/ 和 settings/ 的目录)screenshot -o 指定的是输出目录,不是图片文件名set-component 是否可修改取决于组件类是否实现 setPropbuild 需要在有 library/imports 的 Cocos 项目目录中运行.meta 文件development
查询公网IP地址的地理位置信息,包括国家、省份、城市、ISP、时区等
tools
Cocos Creator 有限状态机 (FSM) 实现,用于管理游戏对象的状态转换
tools
Cocos Creator 2.4.x 粒子系统修饰器开发框架。用于创建、使用和调试自定义粒子修饰器,支持修改粒子位置、颜色、大小、旋转、速度等属性。当需要在 Cocos Creator 中实现复杂的粒子效果控制时使用此技能。
development
使用魔搭平台(ModelScope)API进行图片生成和编辑