I’m working on a project where I have a series of symbols/drawings that are white on transparency. When they are stacked on top of each other (think of Layers) they form another image.
I want the player to be able to tap any of the smaller images and when they do, I want to change the color to show it’s been tapped.
It was recommended that I use masks to do this and I’ve had partial success. Once I got my masks on a 4 byte boundary things started somewhat working.
But here are my problems.
If I apply the mask and setup a touch handler on the layer, the event goes to that layer, but as the mask is applied, :setFillColor does not work.
So I got the bright idea to remove the mask, set the Fill color, then re-apply the mask. When I do this the entire image disappears. In other words, I see the background.
I decided to try (well it was more of a discovery that I was actually not setting the mask back afterwards) not re-set the mask. The :setFillColor works as expected, but now that layer is absorbing all of my touch events since the mask isn’t there.
Is this buggy behavior? Is this what’s to be expected? Here’s my code:
local n = 2
local pics = {}
local mask = {}
bg = display.newRect(0,0,1024,768)
bg:setFillColor(64,256,64)
bg.x = display.contentWidth / 2
bg.y = display.contentHeight / 2
local function fred(event)
print(event.phase,event.target.filename,event.target.index)
if event.phase == "ended" then
event.target:setMask(nil) -- if I don't do this, I don't get a fill
event.target:setFillColor(255,0,0)
print(event.target.mask) -- if I do this, the image disappears
-- if I don't and I remove the mask above
-- my taps get taken by the top layer.
event.target:setMask(event.target.mask)
end
return true
end
for i = 1, n do
pics[i] = display.newImageRect(string.format("image%02d.png",i), 984, 652)
pics[i].x = display.contentWidth / 2
pics[i].y = display.contentHeight / 2
pics[i].filename = string.format("image%02d.png",i)
pics[i].index = i
mask[i] = graphics.newMask(string.format("image%02d\_mask.png",i))
pics[i]:setMask(mask[i])
pics[i].mask = mask[i]
pics[i]:addEventListener("touch",fred)
end
anyone? [import]uid: 19626 topic_id: 24555 reply_id: 324555[/import]