Exactly like Clayton said. I finally figure out how to use mask. It is weird that if I want about ten illuminating areas, I have to call ten backgrounds:
display.setStatusBar( display.HiddenStatusBar )
--Original background
local darkBackground = display.newImage("countrySideDark.jpg")
--Background which reduced saturation and lightness by Photoshop
local lightBackground = display.newImage("countrySide.jpg")
local lightBackground1 = display.newImage("countrySide.jpg")
local halfW = display.contentCenterX
local halfH = display.contentCenterY
--Create lantern
local lantern1 = display.newCircle(0,0,10)
lantern1:setFillColor(0,102,204)
lantern1:translate( halfW, halfH )
local lantern2 = display.newCircle(-200,-200,10)
lantern2:setFillColor(0,204,0)
lantern2:translate( halfW, halfH )
--Create mask
local mask = graphics.newMask( "circlemask.png" )
lightBackground:setMask( mask )
lightBackground1:setMask( mask )
lightBackground1.maskX = lantern2.x - halfW
lightBackground1.maskY = lantern2.y - halfH
--Move light of lantern1
local function moveAround(self)
self.maskX = lantern1.x - halfW
self.maskY = lantern1.y - halfH
end
lightBackground.enterFrame = moveAround
Runtime:addEventListener("enterFrame",lightBackground)
--Move lantern1
function moveLeft(obj)
transition.to(obj,{time=4000,alpha=1,x=obj.x + 300,y=obj.y,onComplete=moveRight})
end
function moveRight(obj)
transition.to(obj,{time=4000,alpha=1,x=obj.x - 300,y=obj.y,onComplete=moveLeft})
end
transition.to(lantern1,{time=4000,alpha=1,x=lantern1.x + 300,y=lantern1.y,onComplete=moveRight})
- I still wonder if corona can reduce the brightness of the image manually in code ?
- And why does the “circlemask.png” 's background in Xray sample in “Sample Projects” have to be black?
I try to change it to light color such as green or red, the mask is weird.
- And tell me if there is another way to create this ?
[import]uid: 111309 topic_id: 19156 reply_id: 74138[/import]