Hello guys, I’m trying to make my app recognise when I press two buttons simultaneously. That’s the code I have written:
----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- local a = display.newCircle( 100, 100, 25 ) a:setFillColor(1, 0, 0) local b = display.newCircle( 200, 100, 25 ) b:setFillColor(0, 0, 1) local flag1=0 local flag2=0 system.activate( "multitouch" ) local function tap1(e) if e.phase=="began" then flag1=1 end end local function tap2(e) if e.phase=="began" then flag2=1 end end local function check() if flag1==1 and flag2==1 then local c=display.newCircle(150, 200 , 25) c:setFillColor(0, 1, 0) flag1=0 flag2=0 elseif flag1==1 and flag2==0 then local c=display.newCircle(150, 200 , 25) c:setFillColor(1, 0, 0) flag1=0 flag2=0 elseif flag1==0 and flag2==1 then local c=display.newCircle(150, 200 , 25) c:setFillColor(0, 0, 1) flag1=0 flag2=0 else local c=display.newCircle(150, 200 , 25) c:setFillColor(1, 1, 1) flag1=0 flag2=0 end return true end a:addEventListener("touch", tap1) b:addEventListener("touch", tap2) Runtime:addEventListener("enterFrame", check)
The problem is: I need to be really precise in touching both at the same time or it won’t be detected as multitouch. How can I fix this? I want the multitouch to be more “tolerant” on pressing timing. Hope I explained the problem properly