I haven’t worked with event.pressure so I can’t speak to what other folks do/would do, but a simple flag seems like it would be the best way to address this, like you would anything else within a touch listener in this fashion. Something like:
local levelTable = { level1, level2, level3, level4, level5, level6, level7, level8, level9, } local level = 1 local levelOn = 1 local canDetectPressure = true local function handlePressureRemoval(set) if set == 1 then if level \< 10 then canDetectPressure = false physics.removeBody( levelTable[level] ) level = level + 1 end elseif set == 2 then end end local function detectTouchPressure(event) if ((event.phase ~= "ended") and canDetectPressure then if event.pressure \>= 2.0 then handlePressureRemoval(1) return true end end if (event.phase == "ended") and not canDetectPressure then handlePressureRemoval(2) return true end end Runtime:addEventListener("touch",detectTouchPressure )
Untested as I don’t have a device that detects pressure at my disposal right now, but I believe that’s the basic gist. The above assumes that you have declared your physics bodies above this touch function.
EDIT: Updating to add a comment that I agree with Rob, in that I have zero idea where a event.pressure event is triggered in a touch listener. I assume it’s phase independent, as you referenced your listener conditions above being fired several times throughout your physical touch. This is all hypothesis on my part though.