Druid's Progress bar - register, initialise

It’s not only you, I often got questions about how to use examples and something about druid.register. I think I should rework it a little to make it much more user friendly

Currently it means that you need to add this lines of code somewhere in your initial collection to add this component inside your game build

local druid = require("druid.druid")
local progress = require("druid.extended.progress")

function init(self)
    druid.register("progress", progress) -- After this line the `self.druid:new_progress` is available
end

After this done, you able to create progress component anywhere in you GUI. So now you need to add the GUI box node at scene, which will be used as a progress node (it’s size will be manages by progress components) and create the progress component itself

-- Inside GUI script
local druid = require("druid.druid")

function init(self)
    self.druid = druid.new(self)
    -- Pass "x" if horizontal, "y", is vertical
    self.progress = self.druid:new_progress("progress_node_id", "x")

    -- Now you can call progress component functions
    self.progress:set_to(0.5)
end

It will looks like the progress example (druid/example/examples/basic/progress_bar/basic_progress_bar.lua at develop · Insality/druid · GitHub) but druid.register already done in the loader collection and whole example code is a Druid custom component intead of gui_script as I provided

2 Likes