Touch Pressure

Oh now understand what he was referencing above. The only issue I have found with targeting one of the touch listeners (such as began) is that it does not detect the pressure properly. Sometimes it works (if I apply the pressure very fast), and other times it doesn’t.

Is there any way around this?

If you’re expecting a tap type action (no movement), then it might be best to use the “ended” phase and it might have the max pressure of the touch. I don’t have a pressure sensitive device to know how this works in reality.

Rob

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.

Hey Alex,

Thank you very much for providing this!

After some small modifications, I got your code working flawlessly on my device. In case other users want to use this, I basically just added the following inside the handlePressureRemoval event.

elseif set == 2 then canDetectPressure = true end

Thanks!

That’s what I get for not taking my time! Glad you got it working!

event.pressure isn’t so much an event, and isn’t “triggered”. It’s just data you get alongside your touch event x/y/phase/etc if the device supports it. You are right, it’s phase-independent.

Hi Alex,

I had a quick question you (or anybody else) could help me out on.  Right now I have the 3d touch working flawlessly (with the code above), however, I would like to trigger a function once if the pressure is not fully applied (grater than or equal to 2.0).

Basically, so that if a normal touch is released, a function is triggered once, whereas if a 3D touch occurs, a second function is triggered once (which works in the code above in this thread).

Thanks