Defold Game Engine

Develop games using Defold engine with Lua scripting, including components, GUI, physics, animation, input handling, dynamic objects, and save/load systems.

Audits

Pass

Install

openclaw skills install defold

Defold Game Engine

Quick Start

Install Dependencies

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

Project Structure

main.collection
├── game_manager.go
├── player.go
└── ui.go

Core Patterns

Message Passing

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

Dynamic Objects

local id = factory.create("#factory", pos, nil, { prop = value })
local ids = collectionfactory.create("#collection_factory")
msg.post("#proxy", "load")  -- Wait for proxy_loaded, then init+enable

GUI (Druid)

self.druid = druid.new(self)
self.btn = self.druid:new_button("node", callback)
self.text = self.druid:new_text("node", "text")

Physics

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

Animation

sprite.play_flipbook("#sprite", "idle", callback)
go.animate(".", "position.y", go.PLAYBACK_ONCE_FORWARD, 100, go.EASING_OUTQUAD, 1.0)

Input

msg.post(".", "acquire_input_focus")

function on_input(self, action_id, action)
    if action_id == hash("jump") and action.pressed then jump() end
end

Save/Load

defsave.load("game")
defsave.set("game", "coins", 100)
local coins = defsave.get("game", "coins")

References

Performance

  • Atlas all sprites
  • Message-driven logic, avoid polling
  • Reuse vectors/tables
  • Engine handles object pooling