I’m was suggested to use masks to solve a problem of wanting to only have touch events active in non-transparent areas of an image. I thought “Great”… my artwork is a series of white and transparency layers that are stacked on top of each other and making the masks would be an exercise is filling in the transparent areas with black.
From that point on my app has been, well not working like I want. My white areas are not showing through and I see all the way through to the bottom. It’s almost like the masks are not masking just the image but all of the images below it.
Fast forward a little. So I now I want to build a small test case to make sure this is really going to work for me, so I put together this very simple app:
bg = display.newRect(0,0,960,640)
bg:setFillColor(128,256,0)
pic = display.newImage("white.png")
pic.x = display.contentWidth / 2
pic.y = display.contentHeight / 2
function fred(event)
print(event.phase)
if event.phase == "ended" then
event.target.alpha = 0.9
event.target:setFillColor(255,255,0)
event.target.alpha = 1.0
end
end
mask = graphics.newMask("mask.png")
pic:setMask(mask)
pic.maskX = pic.x
pic.maskY = pic.y
pic:addEventListener("touch",fred)
In this case, the images are just what you would expect. Redish background with a solid white image and a mask on top of it, some black, some white.
It draws correctly (this isn’t the layer problems I’m experiening) as it should.
But I never get a “began” or “ended” phase in my addEventListener function… I only get “moved”.
I comment out the “setMask” call, and the event listener gets all the events I expect.
It’s been a long weekend and I’m tired of code so I’m assuming I’ve done something stupid here and am just not seeing it. I would hope this isn’t a bug. I really need some time without bugs hindering me.
I’m going to next test my layer theory, and I hope its not a bug either. I need to get this app working.
Can someone with clearer eyes and mind give this a look over? [import]uid: 19626 topic_id: 24217 reply_id: 324217[/import]