Making touchable regions on a background image

I’m trying to figure out what is the best way to do this with Corona. I want to add a background image and I want some regions of this image to be touchable, while the rest of the image not touchable. And I want to know what region was touched.

I thought using a mask on the background image would work, but how would you identify which region was touched?

Any ideas?

One option which i might do in such a situation is to simply create a rectangle display image (or circle if that shape is more appropriate), position it in the appropriate area over the background image and set the alpha to 0. Then you can attach an event listener for that rectangle to listen for touches or taps.

Actually, interestingly, i tend to use .alpha=0.01 rather than 0 - can anyone tell me if that matters at all and/or makes a difference (whether good or bad)?..

Cheers,

Yeah, that would work, unless I really needed pixel-perfect taps. Thanks. Does anyone have another idea?

you could creat a rectangle or circle, set the fill color opacity to 0. that way it will be totally transparent without having to worry about alpha.

if you want it to only be a certain special area of that object add a mask which you set object.isHitTestMasked = true

check mask tutorial here:

http://www.coronalabs.com/blog/2012/05/29/how-to-use-bitmap-masks/

One option which i might do in such a situation is to simply create a rectangle display image (or circle if that shape is more appropriate), position it in the appropriate area over the background image and set the alpha to 0. Then you can attach an event listener for that rectangle to listen for touches or taps.

Actually, interestingly, i tend to use .alpha=0.01 rather than 0 - can anyone tell me if that matters at all and/or makes a difference (whether good or bad)?..

Cheers,

Yeah, that would work, unless I really needed pixel-perfect taps. Thanks. Does anyone have another idea?

you could creat a rectangle or circle, set the fill color opacity to 0. that way it will be totally transparent without having to worry about alpha.

if you want it to only be a certain special area of that object add a mask which you set object.isHitTestMasked = true

check mask tutorial here:

http://www.coronalabs.com/blog/2012/05/29/how-to-use-bitmap-masks/