How can I have touch events ignore transparent bits of an image?

Hi,
Is there a way to have touch events ignore transparant bits?

If I have a donut it should ignore the middle part.

Thanks. [import]uid: 100901 topic_id: 20860 reply_id: 320860[/import]

You can use a bitmap mask, and set the isMaskHittestable property false (default).

The bitmap mask would be black in transparent regions, and white in non-transparent regions. Grey in semi transparent regions (I believe there are tools out there for generating bitmap masks from images).

Here’s the bitmap mask API:
http://developer.anscamobile.com/reference/index/graphicsnewmask [import]uid: 52430 topic_id: 20860 reply_id: 82397[/import]

Hello,
I am using that option, but if you use a mask on a group there seems to be some kind of bug.
Sometimes the touch events come through and sometimes they don’t. So you have to try and keep dragging the group. Without the mask it works but when adding the mask somehow the began phase is missed often.
[import]uid: 100901 topic_id: 20860 reply_id: 82425[/import]

Hey there,

I assume you are the one who filed the bug about this earlier? If so please be aware we are looking into it.

Peach :slight_smile: [import]uid: 52491 topic_id: 20860 reply_id: 82427[/import]

Hi,
yes I submitted the bug after asking the question.
I was hoping someone would offer a solution other than the mask option.

[import]uid: 100901 topic_id: 20860 reply_id: 82434[/import]

Peach > Any news about that?
I’m facing the same issues (when scaling the display group). [import]uid: 95346 topic_id: 20860 reply_id: 88016[/import]

I’m unsure if it has been fixed or not, will look into it today - although if it has this will be in daily builds only. [import]uid: 52491 topic_id: 20860 reply_id: 88052[/import]

Hi, Peach!

Is Transparency Touch problem fixed in your Daily Builds? I cant find any info about this:( [import]uid: 121061 topic_id: 20860 reply_id: 93491[/import]

Altaev, I believe the mask issue was fixed however I’m not 100% on that, you can add a mask to one of our samples to easily check this, though, assuming you are a licensed Corona developer?

If not, let me know, will try make time to test it this evening and get back to you. [import]uid: 52491 topic_id: 20860 reply_id: 93669[/import]

Just throwing this out there, another approach to this (a little lazier and less customizable) is to to check the coordinates of the touch input and compare them to the center of the object you want to touch. Using this, it’s pretty easy to filter out custom circle and square areas (just as long as you make the transparent image large enough).

The bitmap solution is probably better suited and more efficient, but just in case:

local distBetween(a, b)  
 local xDiff = b.x-a.x  
 local yDiff = b.y-a.y  
 return sqrt((xDiff\*xDiff) + (yDiff\*yDiff))  
end  
  
local function circleContains(center, point, dist)  
 return distBetween(center, point) \<= dist  
end  
  
local function donutContains(center, point, min, max)  
 local dist = distBetween(center, point)  
 return dist \>= min and dist \<= max  
end  
  
local function squareContains(rect, p)  
 local hw = rect.width \* 0.5  
 return p.x \>= rect.x - hw and p.y \>= rect.y - hw and p.x \<= rect.x + hw and p.y \<= rect.y + hw  
end  
  
local function onDonut(event)  
 local targ = event.target  
 -- if (squareContains(targ, event)) then  
 -- if (circleContains(targ, event, 100)) then  
 if (donutContains(targ, event, 50, 100)) then --Tap within a 50-100 px radius  
 -- handle each phase, make sure to use the touch (not tap) listener  
  
 -- return true inside to otherwise allow propagation outside the custom area  
 return true  
 end  
end  

I find that approximating these things with circles or squares is usually accurate enough for my needs. Easy to adjust on the fly too :slight_smile: [import]uid: 87138 topic_id: 20860 reply_id: 93682[/import]

Peach, for my situation i need to have a possibility to ignore object transparency when it dragging without a trick such as masks and other(my project will have a 50+ objects and create a custom mask for each of them is a big additional job:( ) Right now i’m not a licenced developer and want to know is this transparency bug fixed in last Daily Builds?

[import]uid: 121061 topic_id: 20860 reply_id: 93828[/import]

It’s not actually a bug; it’s something we’re looking into solutions for and masks is one of those things; it isn’t a trick, it’s a solution.

There are other great solutions such as Revaerie’s suggestion above. [import]uid: 52491 topic_id: 20860 reply_id: 94024[/import]