Hi all,
I’m using @britzl’s onsreen.lua module (GitHub - britzl/defold-input: Simplify input related operations such as gesture detection, input mapping and clicking/dragging game objects) to have two analog sticks in my mobile game. One is for movement, the other is for rotation…
I’ve found that they both work individually i.e. I can move OR I can rotate, but they won’t work if I try and move them both at the same time - whatever I touch first maintains the input focus and the other one won’t do anything.
Is there anything special I need to do here?
Here is the init code:
function init(self)
msg.post("/level#onscreen", "register")
msg.post("/level#onscreen", "register_analog", { id = "analog_move", radius = 80 })
msg.post("/level#onscreen", "register_analog", { id = "analog_shoot", radius = 80 })
end
And here is the input handling code:
function on_message(self, message_id, message, sender)
elseif message_id == hash("onscreen_analog") then
if message.id == hash("analog_move") then
if message.released then
self.speed.x = 0
self.speed.y = 0
else
self.speed.x = message.x * 200
self.speed.y = message.y * 200
end
elseif message.id == hash("analog_shoot") then
local angle = math.atan2(message.y, message.x)
self.dir = vmath.quat_rotation_z(angle + math.rad(90))
end
end
end