Way to simulate a touch even in code?

I’m wondering if there is way to simulate the user “touching” an object but instead of them having to touch the screen do it in code?

I found a work around I just created a table and “simulated” the event table and passed that into the function that the touched listener called. May not be the best way of doing it but it’s for GIGjam and there is less then 23 hours left so it will have to do :smiley:

I found a work around I just created a table and “simulated” the event table and passed that into the function that the touched listener called. May not be the best way of doing it but it’s for GIGjam and there is less then 23 hours left so it will have to do :smiley:

When I faced with such problem, I created function for my display object that should be touched. Something like this

local function onTouch (event) if (event.phase == "began") then -- do something end end local image = display.newImageRect (...) image:addEventListener ("touch", onTouch) function image:emulateTouch () local event = {} -- create event table event.phase = "began" -- and then we set all needable variables that usually we procced in the listener onTouch (event) -- and just call our function end  

Also, consider the “dispatchEvent()” API. Among various other useful things, this can be used to dispatch a “touch that’s not actually a touch” to an object. I use this occasionally and it’s a great tool to understand and utilize.

http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html

Best regards,

Brent

When I faced with such problem, I created function for my display object that should be touched. Something like this

local function onTouch (event) if (event.phase == "began") then -- do something end end local image = display.newImageRect (...) image:addEventListener ("touch", onTouch) function image:emulateTouch () local event = {} -- create event table event.phase = "began" -- and then we set all needable variables that usually we procced in the listener onTouch (event) -- and just call our function end  

Also, consider the “dispatchEvent()” API. Among various other useful things, this can be used to dispatch a “touch that’s not actually a touch” to an object. I use this occasionally and it’s a great tool to understand and utilize.

http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html

Best regards,

Brent