I have a problem because I don’t know how to detect (mobile version in html) an event when a user holds down for example the “left” button and clicks “jump”. It always either detects left or jump for me, never both at the same time,
Here it is the same, I can control the rocket, but I can’t shoot at the same time. Is this a problem of html version ?
There is my code
function on_input(self, action_id, action)
local up_node = gui.get_node("up")
local left_node = gui.get_node("left")
local right_node = gui.get_node("right")
if action_id == hash("Mtouch") then
if action.touch then
for _,touchpoint in ipairs(action.touch) do
if gui.pick_node(left_node, action.x, action.y) then
if action.pressed then
msg.post("/player/player#player", "tap_left", { action = -1 })
elseif action.released then
msg.post("/player/player#player", "tap_left", { action = 0 })
end
end
if gui.pick_node(right_node, action.x, action.y) then
if action.pressed then
msg.post("/player/player#player", "tap_right", { action = 1 })
elseif action.released then
msg.post("/player/player#player", "tap_right", { action = 0 })
end
end
if gui.pick_node(up_node, action.x, action.y) then
if action.pressed then
msg.post("/player/player#player", "tap_up", { action = 1 })
elseif action.released then
msg.post("/player/player#player", "tap_up", { action = 0 })
end
end
end
end
end
end
With the generic solution I suggested above (using the onscreen.lua module in Defold-Input) it’s easy to add any configuration you want. Here’s an example with two buttons and an analog stick (remove the code for the analog stick if you don’t need it):
I don’t think it’s out yet but apple has a new software controller they’re debuting: Apple Developer Documentation which obviously is a single platform but seems decently interesting if someone can do a wrapper for it.