Hey all,
I’m trying to create a ‘turret’ which shoots as long as you keep touching it. I have this listener;
local function autoTurretTouchListener(e) if(isGamePaused == false) then local turret = e.target if (e.phase == "began") then if(turret.shootingTimer == nil) then turret.shootingTimer = timer.performWithDelay(turret.fireRate, function() turret:spawnBall() end, 0) end timer.resume(turret.shootingTimer) elseif e.phase == "ended" then if(turret.shootingTimer ~= nil) then timer.pause(turret.shootingTimer) end end end end
It works as expected but if you press inside the ‘turret’ object and drag the touch out of the object it won’t stop shooting because it doesn’t get the “ended” event.phase. I couldn’t come up with a workaround for this. I tried with global touch listener but you can’t get event.target so it was no use.
And I have multiple turrents on-screen at once. I was thinking about adding a global touch listener and in the “ended” phase, loop thru all the turrets to make them stop shooting but I was hoping there would be a better solution… Any help is appreciated.