Listeners on objects - How to handle touch events the right way?

Hi, I’m a new user and I am still learning how to code.

My question is : how would you handle touch events on specific objects?
From what I could understand in the examples provided, the touch event is offen handled the following way (pseudo code) :
if user touches the screen and the coordinates of the touch event are whithin a certain area, then object was touched.

I would like to know if I can create listeners so that :
if object is touched then do something.

The difference is that Codea would handle the touch event for me, I would put a few buttons on the screen (gamepad) and I wouldn’t have to check touch event coordinates each time.

Can you tell me how to achieve that in Codea?
Thank you!

You can have each object/button have it’s own touch function but you still have to make sure to call them all.

The touch function for the object/button doesn’t have to be called touch or even be a seperate function.

You could also have a common button/object/function that checks “if a touch is near me return true”

There are no built in higher level buttons but some have posted control libraries.

mells, what you describe is not built into codea. Checking each object is the best way. Does that not work for you?

I do this by having a meta-touch handler that gathers all the touches. It then queries each object that it knows about to see if they were the one touched (only at the start of the touch). Then each object defines a callback function and the touch handler calls that function with all of the touches associated to that object.

My code is available from my website: The touch handler is fairly stable - I haven’t had to add anything to that code for a while.

(Once 1.3 comes out then it’ll be easier to get hold of as it’ll be in one of the examples.)

Prior discussion with example on touch events, hope it helps

Also found this discussion on rounded corners you may find helpful

In Visual Studio language implementations, Microsoft often hides the event loop, so that all you see are the responses to events – which can be handy. However, I think I prefer the clear execution you get in Codea. If nothing else you’re never in doubt about order of events.

Oh, and Andrew’s touch handler goes a long way in neat ending your code.

( Wow, Great community!) Thank you very much, that’s more than I was asking :slight_smile: