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
msg.post("/gui#gui", "add_bomb")
launch_bomb = false
break
end
end
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
msg.post("/gui#gui", "minus_bomb")
end
end
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