Multitouch in html [SOLVED]

Hi !

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,

I reviewed an example.
http://britzl.github.io/publicexamples/virtual_gamepad/index.html

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

Could you please try this example instead:

https://britzl.github.io/Defold-Input/

It is based on the most up-to-date version I have created of how to create on-screen virtual controls:

1 Like

Is there any example with just buttons without gamepad ?

I don’t see any issues with your code snippet. I’d debug which events you are receiving in the on_message function. Btw, is “up” the shooting action?

No. There is only a left and right movement and a jump.

But you mention you can’t shoot?

I can control the rocket, but I can’t shoot at the same time

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):

2 Likes

thanks. It works perfect.

2 Likes

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.

1 Like

Hi !!
I have a problem with multitouch under IOS 15. It doesn’t work properly. Your example too

We’ll have to look into this. This is the first time I’ve heard of this issue.

1 Like