Touch controls incorrectly doubling up (SOLVED)


Hi guys I’m trying to get some touch controls working for a mobile game. I’ve got an html version too because it makes testing easier in theory. With the mobile version touches are registering twice and I’m not sure why. Re: Controls, I’ve got two different parts of the screen. When you touch one section your number of bombs should increase by 1. When you touch the other section you launch a bomb and your number of bombs should decrease by 1. This output works for the html version but the mobile version increases by 2 and decreases by 2 with the same actions. Wondering if touch inputs work slightly differently from mouse inputs? Here’s my code (the important part I think is the first line)…

if action_id == hash("mouse") and action.released or action_id == hash("touch") and action.released then
		local launch_bomb = true -- flag so only one bomb will launch
		for i = 1, #self.bottable do 
			local pos = go.get_position(self.bottable[i])
			local distance = vmath.length(vmath.vector3(action.x, action.y, pos.z) - pos )
			if distance <= 100 then 
				self.bombs = self.bombs + 1"/gui#gui", "add_bomb")
				launch_bomb = false
		if launch_bomb and self.bombs > 0 then
			local b = factory.create("#bombfactory", vmath.vector3(action.x, 250, 0), nil, {player = 1}, 2)
			self.bombs = self.bombs - 1"/gui#gui", "minus_bomb")

I tried changing action.released in the hash(‘touch’) part to “#action.touch == 1” but that registered many many more touches than what I have in place already. Any ideas why I’m doubling up with one version and not the other? Cheers :slight_smile:



Do you have input bindings for both mouse and touch triggers? On device the mouse is “emulated”, so you would effectively get both multitouch input and a “mouse” input. :slight_smile:


Thanks for the quick reply. This is what I’ve got setup at the moment. I think I’ve got both set up


Yup, seems that you both have mouse and touch triggers (I should have figured that out by the first code you posted, my bad). :slight_smile:

There is nothing wrong with that per se, for game input it might make sense to have multi touch support, while in GUI it could make more sense to only listen/use the emulated mouse inputs…

I would recommend to use only the mouse inputs in any GUI (or “gui like” stuff in the collection) you have, in your case just removing the action_id == hash("touch") check.


Thanks! That worked :grin: