Defold Game Engine — Defold 游戏引擎
v1.0.0使用Defold引擎和Lua脚本开发游戏,包括组件、GUI、物理、动画、输入处理、动态对象和保存/加载系统。
运行时依赖
安装命令
点击复制技能文档
Defold 游戏引擎快速入门 安装依赖 https://github.com/Insality/druid/archive/refs/tags/1.2.2.zip https://github.com/subsoap/defsave/archive/refs/tags/v1.2.6.zip https://github.com/insality/defold-monarch/archive/1.0.zip 项目结构 main.collection ├── game_manager.go ├── player.go └── ui.go 核心模式 消息传递 msg.post("target#script", "event", { data = value }) function on_message(self, message_id, message, sender) if message_id == hash("event") then handle(message) end end 动态对象 local id = factory.create("#factory", pos, nil, { prop = value }) local ids = collectionfactory.create("#collection_factory") msg.post("#proxy", "load") -- 等待 proxy_loaded,初始化并启用 GUI (Druid) self.druid = druid.new(self) self.btn = self.druid:new_button("node", callback) self.text = self.druid:new_text("node", "text") 物理 physics.apply_force("#collision", force) physics.set_velocity("#collision", velocity) function on_message(self, message_id, message, sender) if message_id == hash("collision_response") then handle_collision(message.other_id, message.normal) end end 动画 sprite.play_flipbook("#sprite", "idle", callback) go.animate(".", "position.y", go.PLAYBACK_ONCE_FORWARD, 100, go.EASING_OUTQUAD, 1.0) 输入 msg.post(".", "acquire_input_focus") function on_input(self, action_id, action) if action_id == hash("jump") and action.pressed then jump() end end 保存/加载 defsave.load("game") defsave.set("game", "coins", 100) local coins = defsave.get("game", "coins") 参考 核心概念:core-concepts.md - GO、组件、寻址、生命周期 GUI 系统:gui-system.md - 节点、布局、Druid 动态对象:dynamic-objects.md - 工厂、集合工厂、代理 数据存储:data-storage.md - sys.save、DefSave、io.* 物理:physics-system.md - 碰撞、力、射线 动画:animation-system.md - Flipbook、Spine、go.animate 输入:input-system.md - 绑定、焦点、on_input 游戏模式:business-patterns.md - 客户、商店、升级 性能 Atlas 所有精灵 消息驱动逻辑,避免轮询 重用向量/表格 引擎处理对象池