britzl / defold-input

Simplify input related operations such as gesture detection, input mapping and clicking/dragging game objects
MIT License
111 stars 26 forks source link

Can not use gui.clone as buttons #5

Closed Jerakin closed 5 years ago

Jerakin commented 5 years ago

Registering buttons created from nodes overwrite each other. hash_to_hex(gui.get_id(node)) is identical for clones.

https://github.com/britzl/defold-input/blob/a9cceb9c96d3fe25aacfba3bba975d02b0632b74/in/button.lua#L38

local function node_to_key(node)
    local url = msg.url()
    return hash_to_hex(url.socket) .. hash_to_hex(url.path) .. hash_to_hex(url.fragment) .. hash_to_hex(gui.get_id(node))
end

function init(self)
    self.clone = gui.get_node("clone")
    for i=1, 10 do 
        local c = gui.clone(self.clone)
        print(node_to_key(c))
    end
end
britzl commented 5 years ago

You could manually generate and set an id using gui.set_id() to fix this. I did however add code to assign an auto-generated id to button nodes that have no id (empty hash).

https://github.com/britzl/defold-input/releases/tag/1.5.1