Dual virtual analog joysticks not working in parallel

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

is multitouch enabled in your input?

1 Like

hey @gianmichele - where would I enable multitouch?

My gamepad gui links to the standard onscreen.gui_script in the module (defold-input/onscreen.gui_script at master · britzl/defold-input · GitHub), and the code for for posting messages to that is shown above.

How to enable multi touch:

2 Likes

Ah Mathias was faster than me.
Yes in the input binding you need to ass the touch multi input.

Legends! Thanks both…

For anyone else stumbling on this, as per the guidance I enabled multi touch as per these docs - Mouse and touch input in Defold. I only needed to do this step:

image

2 Likes

I’m happy the on-screen controller script was useful to you. I’m quite happy with how it works, but I’d be happy to hear if you have any feedback or suggested improvements. I’ll take a look at the docs to clarify on multi touch input.

1 Like

Added note about multi-touch: defold-input/onscreen.md at master · britzl/defold-input · GitHub

1 Like