Made a transparent portion on background (lightspot effect)

1 vote · 0 comments

This is how you make a light spot effect on a big background. like this video: spotlight

Hope this will help.

raw ·
copy
· download
MOAISim.openWindow ( "Light In The Darkness", 1024, 768 ) viewport = MOAIViewport.new () viewport:setSize ( 1024, 768 ) viewport:setScale ( 1024, 768 ) layer = MOAILayer2D.new () layer:setViewport ( viewport ) MOAISim.pushRenderPass ( layer ) gfxQuad = MOAIGfxQuad2D.new () gfxQuad:setTexture ( "fire-background.png" ) gfxQuad:setRect ( -400, 225, 400, -225 ) gfxQuad:setUVRect ( 0, 0, 1, 1 ) fireBg = MOAIProp2D.new () fireBg:setDeck ( gfxQuad ) layer:insertProp ( fireBg ) fireBg:setLoc(0, 0) fireBg:setPriority(10) darkQuad = MOAIGfxQuad2D.new () darkQuad:setTexture ( "background-dark-2.png" ) darkQuad:setRect ( -256, -256, 256, 256 ) darkQuad:setUVRect ( 0, 0, 1, 1 ) darkBg = MOAIProp2D.new () darkBg:setDeck ( darkQuad ) layer:insertProp ( darkBg ) darkBg:setLoc(0, 0) darkBg:setBlendMode(MOAIProp2D.GL_ONE, MOAIProp2D.GL_ONE_MINUS_DST_ALPHA) darkBg:setColor(0, 0, 0, 1) darkBg:setPriority(30) lightQuad = MOAIGfxQuad2D.new () lightQuad:setTexture ( "background-light.png" ) lightQuad:setRect ( -128, -128, 128, 128 ) lightQuad:setUVRect ( 0, 0, 1, 1 ) lightBg = MOAIProp2D.new () lightBg:setDeck ( lightQuad ) layer:insertProp ( lightBg ) lightBg:setLoc(150, 0) lightBg:setBlendMode(MOAIProp2D.GL_ZERO, MOAIProp2D.GL_ONE_MINUS_SRC_COLOR) lightBg:setColor(0, 0, 0, 1) lightBg:setPriority(20) function pointerCallback ( x, y ) mouseX, mouseY = layer:wndToWorld ( x, y ) lightBg:setLoc(mouseX, mouseY) if MOAIInputMgr.device.mouseLeft:isUp () then end end MOAIInputMgr.device.pointer:setCallback ( pointerCallback )

Be the first to comment

Sign in with OpenID