I’ve been following the instructions here https://docs.coronalabs.com/guide/media/imageMask/index.html to create a mask with hit masking.
The object I’m masking is a big blue rectangle. The mask is a black rectangle with a small white square in the center. My expected outcome is that when the mask is implemented, the big blue rectangle will be transparent, except for the small square at the center of the mask. The hit masking should mean that only taps on the unmasked portion of the blue rectangle should be registered.
My mask image meets these requirements:
The mask image must have width and height dimensions that are divisible by 4.
The mask image must be bordered by at least 3 pixels of black space on all four sides. You may need to increase the overall size of your mask image to include this border.
If the mask image is smaller than the target image, the region outside of the mask bounds will be fully masked (transparent).
Here is my code:
1 image = display.newImage(“blueBox.png”, centerX, centerY)
2 local mask = graphics.newMask(“mask.png”)
3 image:setMask(mask)
4 image.isHitTestMasked = true
If I include all 4 lines, the result is that nothing appears and there is no hit masking (a click anywhere is registered).
If I comment out line #4, I get the same result as above.
If I comment out lines #3 and #4, I get my image (the big blue rectangle), but no mask and no hit masking.
Am I missing something? Or is masking not working properly?