Skip to content

Instantly share code, notes, and snippets.

View XeduR's full-sized avatar

Eetu Rantanen XeduR

View GitHub Profile
@XeduR
XeduR / cancelTouch.lua
Last active April 19, 2021 11:52
A method for forcibly cancelling touch events in Solar2D programmatically regardless of the active touch event's phase.
local masterTouch
local function cancelTouch()
if masterTouch then
print( "\nTouch event phase before cancellation: " .. masterTouch.phase )
-- You could include a unique property to know that the event was terminated via this function.
-- masterTouch.terminated = true
masterTouch.phase = "cancelled" -- Change the event phase before faking the touch event.
masterTouch.target.listener( masterTouch )
-- Setting isTouched property back to false will prevent the touch listener from firing again