setMask on two separate groups makes their alpha interfere with each other

Hello,

I’m seeing something strange when using masks.

I have several separate groups which each are masked. The mask dimensions are dividable by 4 and have a 3 pixel black border. The mask itself contains some white and some gray. Running Corona Version 2014.2189 (2014.3.6), device: Ipad 3 & 4 latest and previous iOS versions.

The strange part is that the group created first have less transparency in the gray part of the mask than the group created last.

I have attached the image and mask used, and below is the code:

local bg = display.newRect(0, 0, 1024, 768) bg:setFillColor(1, 1) bg.anchorX, bg.anchorY = 0, 0 local asset = { path = 'log\_long.png', width = 585, height = 134 } local maskPath = 'log\_long\_watermask\_blackborders.png' local grp1 = display.newGroup() local mask1 = graphics.newMask(maskPath) local img1 = display.newImageRect(asset.path, asset.width, asset.height) grp1:setMask(mask1) grp1:insert(img1) grp1.x, grp1.y = 400, 100 local grp2 = display.newGroup() local img2 = display.newImageRect(asset.path, asset.width, asset.height) local mask2 = graphics.newMask(maskPath) grp2:setMask(mask2) grp2.x, grp2.y = 550, 250 grp2:insert(img2) local grp3 = display.newGroup() local mask3 = graphics.newMask(maskPath) local img3 = display.newImageRect(asset.path, asset.width, asset.height) grp3:setMask(mask3) grp3:insert(img3) grp3.x, grp3.y = 400, 400 local grp4 = display.newGroup() local mask4 = graphics.newMask(maskPath) local img4 = display.newImageRect(asset.path, asset.width, asset.height) grp4:setMask(mask4) grp4:insert(img4) grp4.x, grp4.y = 400, 550 -- changing the z-index you can see how the masks affect each other --grp1:toFront()

This seems like a Corona bug to me, but if it is not, and I have done some mistake in my code, no one would be happier than me (release day coming soon). Please help.

Kind Regards,

Hi, did you fix this problem? I’m having a similar problem with 2 groups with different masks.

Hi @borriero,

Can you please post your code which exhibits this, so I can compare it to that from @fredrikvestin?

Thanks,

Brent

local group1 = display.newGroup() local group2 = display.newGroup()   local mask = graphics.newMask("mask.png") group1:setMask(mask) group1.maskX = 200 group1.maskY = display.contentCenterY   --local mask = graphics.newMask("mask.png") --local mask = graphics.newMask("mask2.png") group2:setMask(mask) group2.maskX = 200 + display.contentCenterX group2.maskY = display.contentCenterY   local obj obj = display.newRect( 0, 0, 1000, 150 ) obj:setFillColor( 0, 0, 1, 0.4 ) obj.x = display.contentCenterX obj.y = display.contentCenterY group1:insert(obj)   obj = display.newRect( 0, 0, 1000, 500 ) obj:setFillColor( 1, 0, 0, 0.4 ) obj.x = display.contentCenterX obj.y = display.contentCenterY group2:insert(obj)

Check that code for example…

This is the mask

mask.png

If you see one group should show a red rectangle and the other a blue one, but they are overlapped because of the alpha.

See this:

screenshot.png

I hope you can understand it.

I forgot to tell you that I tested loading diferent mask files and they are wrong too.

Hi @borriero,

I’ll probably need to investigate/test this a bit before I know what’s going on. In the meantime, have you considered using containers for this, instead of masks?

Brent

I didn’t, it still looks this way in our live app. Someone might find it a little bit odd, but it is certainly not a show-stopper for our app so I just let it be. It’s still an aesthetic issue though so I’m curious to see any solution or work-arounds.

Best Regards,

This is a critical bug for my app. Is it in the pipe to be fixed?

In my case, I’m waiting for it to migrate my app to graphics 2.0. In 1.0 it was working properly.

Hi @borriero,

Can you please submit your test case as a bug report?

http://developer.coronalabs.com/content/bug-submission

However, since you are waiting on this before migrating, I strongly suggest that you use containers, as (it appears) your masks are basic rectangles, and that is an ideal use-case for containers. You now have access to containers at the Pro tier in Graphics 2.0, and I think you’ll find them considerably easier to apply than masks (no need for mask images, no need to create mask objects, etc.)

Best regards,

Brent

Hi, did you fix this problem? I’m having a similar problem with 2 groups with different masks.

Hi @borriero,

Can you please post your code which exhibits this, so I can compare it to that from @fredrikvestin?

Thanks,

Brent

local group1 = display.newGroup() local group2 = display.newGroup()   local mask = graphics.newMask("mask.png") group1:setMask(mask) group1.maskX = 200 group1.maskY = display.contentCenterY   --local mask = graphics.newMask("mask.png") --local mask = graphics.newMask("mask2.png") group2:setMask(mask) group2.maskX = 200 + display.contentCenterX group2.maskY = display.contentCenterY   local obj obj = display.newRect( 0, 0, 1000, 150 ) obj:setFillColor( 0, 0, 1, 0.4 ) obj.x = display.contentCenterX obj.y = display.contentCenterY group1:insert(obj)   obj = display.newRect( 0, 0, 1000, 500 ) obj:setFillColor( 1, 0, 0, 0.4 ) obj.x = display.contentCenterX obj.y = display.contentCenterY group2:insert(obj)

Check that code for example…

This is the mask

mask.png

If you see one group should show a red rectangle and the other a blue one, but they are overlapped because of the alpha.

See this:

screenshot.png

I hope you can understand it.

I forgot to tell you that I tested loading diferent mask files and they are wrong too.

Hi @borriero,

I’ll probably need to investigate/test this a bit before I know what’s going on. In the meantime, have you considered using containers for this, instead of masks?

Brent

I didn’t, it still looks this way in our live app. Someone might find it a little bit odd, but it is certainly not a show-stopper for our app so I just let it be. It’s still an aesthetic issue though so I’m curious to see any solution or work-arounds.

Best Regards,

This is a critical bug for my app. Is it in the pipe to be fixed?

In my case, I’m waiting for it to migrate my app to graphics 2.0. In 1.0 it was working properly.

Hi @borriero,

Can you please submit your test case as a bug report?

http://developer.coronalabs.com/content/bug-submission

However, since you are waiting on this before migrating, I strongly suggest that you use containers, as (it appears) your masks are basic rectangles, and that is an ideal use-case for containers. You now have access to containers at the Pro tier in Graphics 2.0, and I think you’ll find them considerably easier to apply than masks (no need for mask images, no need to create mask objects, etc.)

Best regards,

Brent