defold-core
它能做什么
该技能讲解如何组织和修复用 Lua 编写的 Defold 游戏,包括其项目文件、脚本和消息。适合使用 Defold 游戏引擎的开发者。
适用场景
- ✓当 Defold 项目中有你需要修改的 game.project 文件、集合、游戏对象或脚本文件时。
- ✓当你需要对象在 Defold 中发送消息、在运行时生成,或加载新关卡时。
- ✓当 Defold 构建报告缺少资源,而你需要找出原因时。
技能链接
https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/other-engines/defold-core/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“在我的 Defold 游戏中,我需要敌人每隔几秒在随机位置出现,你能帮我设置吗?”
每周 5 个新技能,1 分钟读完。
工作原理
该技能指导智能体读取项目设置,为每个部分编辑正确类型的文件,遵循现有的命名规则,并运行构建检查以确认游戏正常工作。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Defold Core
Structure, wire and verify a Defold game: editor resource files, the Lua script lifecycle, addressing and messages, runtime spawning and world loading, and a Bob build-and-run check. Examples target Defold 1.14.0; they were built with Bob 1.14.0 and run on the 1.14.0 headless engine. An existing project keeps its Defold version (see Version).
When to use
- Use when adding or fixing game objects, collections, scripts, input, messages, spawning or
level loading in a Defold project (
game.projectin the root,.collection,.go,.script,.gui_scriptfiles), or when Bob reports a missing resource.
When not to use: plain Lua or LÖVE projects (love2d-core); GUI layout, sprites,
tilemaps and physics depth beyond the pointers in the references; engine-agnostic design
handled by the related skills below.
Workflow
- Inspect first. Read
game.project([bootstrap] main_collection,[input] game_binding,[project] dependencies), the main collection, and the scripts near the request. Follow the project's folder layout, id naming and message names; do not reorganize. Note which Defold/Bob version CI or the team uses. - Edit the right file type. Game objects (
.go) hold components; collections (.collection) place game objects and other collections; logic goes in.script(game objects),.gui_script(GUI) or shared.luamodules. Editor files are protobuf text: keep their structure, and copy shapes fromreferences/file-formats.mdinstead of guessing fields. - Check references. Run
python scripts/check_defold_project.py <project-dir>(path relative to this skill folder; Python 3.10+, no Defold install needed). Fix everyERROR(missing or wrong-case/paths, agame.projectpath without the compiledcsuffix, arequirewhose file does not exist). Warnings cover files nothing uses yet, unfetched library dependencies and runtime-loaded files. Re-run until it exits 0. - Build with Bob.
java -jar bob.jar --root . --variant headless --archive resolve buildneeds JDK 25 and abob.jarmatching the project's Defold version. Exit 1 plus anERROR:line means a broken reference or a Lua syntax error (with file and line);references/file-formats.mdshows how to trace an error that names a generated file. - Run it. A build does not prove the game works. Run a headless bundle under a timeout
(
references/build-and-run.md) and read the log:ERROR:SCRIPT:lines are Lua runtime errors,ERROR:GAMEOBJECT:lines bad addresses or socket clashes. Require a line your test prints when it finishes; the exit code alone proves nothing. The headless engine has no keyboard or mouse, so check input changes in the editor or a desktop build, and say what you could not verify.
Patterns
Project and resource references
game.project is an INI file in the project root. Resource paths everywhere are
root-absolute (/main/player.go). In game.project they name the compiled file, so the
source path gets a trailing c:
[bootstrap]
main_collection = /main/main.collectionc
[input]
game_binding = /input/game.input_bindingc
Bob builds only what is reachable from game.project; /builtins/... ships with the engine.
Collections, game objects, components
A collection places instances and can override script properties per instance; a game object
lists file components and embedded components (escaped data: strings). Full verified
files are in references/file-formats.md.
# main.collection (excerpt): place player.go and override its script's speed
instances {
id: "player"
prototype: "/main/player.go"
component_properties {
id: "player"
properties { id: "speed" value: "250.0" type: PROPERTY_TYPE_NUMBER }
}
}
Script lifecycle, self and properties
go.property("speed", 200) -- top level only, literal default; editable per instance
local LEFT = hash("left") -- hash ids once, not every frame
local RIGHT = hash("right")
local FIRE = hash("fire")
function init(self)
msg.post(".", "acquire_input_focus") -- no focus, no on_input calls
self.held = {} -- per-instance state lives on self
end
function update(self, dt)
local dir = (self.held[RIGHT] and 1 or 0) - (self.held[LEFT] and 1 or 0)
if dir ~= 0 then
local pos = go.get_position()
pos.x = pos.x + dir * sel
常见问题
Defold 中的集合是什么?
集合是一个文件,用于在关卡中放置游戏对象和其他集合。
什么是 Bob?
Bob 是 Defold 的构建工具,该技能用它来构建游戏并进行快速检查。
它涵盖 GUI 布局吗?
涵盖得不深入。GUI 布局、精灵和瓦片地图只会被提及,并未完整涵盖。
详情
作者的原始描述
Build and debug the core of a Defold game in Lua: game.project settings, collections, game objects and components, script lifecycle and self state, go.property, input focus and bindings, URLs and message passing, factories, collection factories and collection proxies, plus building and smoke-running with Bob. Use when a project has game.project or .collection, .go, .script, .gui_script or .input_binding files, or the request mentions Defold, msg.post, on_message, on_input, acquire_input_focus, factory.create, collection proxy, bob.jar, or a Defold build error.
热度
- GitHub 星标
- 6.6k
- 排名
- #13833
- 许可证
- Apache-2.0
- 更新时间
- 2026/10/28
评论
- …