Detect when screen is touched

How would I detect the screen being touched? I want to tap the screen to pause my game, just like tilt monster. I already have the code to pause, just need to know how to have touching the screen tell the game to pause.

Thanks a lot! [import]uid: 9968 topic_id: 4625 reply_id: 304625[/import]

Runtime:addEventListener(“tap”, yourPauseFunction);

or

Runtime:addEventListener(“touch”, yourPauseFunction);

but you have to play with event.phase to not get tricky bugs. [import]uid: 8486 topic_id: 4625 reply_id: 14617[/import]

Hmm, I couldn’t get this to work at all, I tried multiple event.phases but nothing worked by touching the screen. Is there something I am missing?

Thank you for your help!

-Kyle [import]uid: 9968 topic_id: 4625 reply_id: 14632[/import]

Have you tried just “tap” ? not the touch one.
With touch, you have to choose if call the function when touch begins or when touch ends.
With tap it will be called when you tap the screen.
Try this code:

local checkTouch = function(event)  
 if event.phase == "ended" then  
 print ("You touched me!")  
 end  
end  
  
Runtime:addEventListener("touch", checkTouch);  

If it works ok, and it prints that message in your console, than just swap that function with your pause function. If it doesn’t work, then maybe there’s a problem with your pause function. [import]uid: 8486 topic_id: 4625 reply_id: 14670[/import]