Is there a way to make a radial mask (spotlight) using filters or blends?

Think of a find-in-the-dark-using-spotlight puzzle. There is an image, on top an opaque black rectangle, and on top a radial spotlight that allows to see through the black rectangle.

One way to achieve this effect is with graphics.newMask(). But that requires preparing a file. Is there another way to do this using the new filters/blends/snapshots/something else ?

What if the spotlight must have a gradient alpha?

Totally possible. I accomplished this by using porter/duff blend modes. You can take a look at the source code I posted here: http://forums.coronalabs.com/topic/41510-2-demos-for-the-contest/ I used images because I had some performance issues when using 10-20 spotlights but you could use circles with the generator.radialGradient fill effect.

Basically you are looking for this code:

--inside swcaster/engine.lua snapshotMask     = display.newSnapshot(engine, width, height) local r = display.newRect(snapshotMask.group, 0, 0, width, height) r:setFillColor(0, 1) --and then swcaster/light.lua function \_createMask()         local m = display.newImageRect("img/lightMask.png", 256, 256) -- this image is inserted in the mask snapshot group         m.blendMode = "dstOut"         return m end  

Hope it helps.

Ivan.

Thank you, Ivan!

Totally possible. I accomplished this by using porter/duff blend modes. You can take a look at the source code I posted here: http://forums.coronalabs.com/topic/41510-2-demos-for-the-contest/ I used images because I had some performance issues when using 10-20 spotlights but you could use circles with the generator.radialGradient fill effect.

Basically you are looking for this code:

--inside swcaster/engine.lua snapshotMask     = display.newSnapshot(engine, width, height) local r = display.newRect(snapshotMask.group, 0, 0, width, height) r:setFillColor(0, 1) --and then swcaster/light.lua function \_createMask()         local m = display.newImageRect("img/lightMask.png", 256, 256) -- this image is inserted in the mask snapshot group         m.blendMode = "dstOut"         return m end  

Hope it helps.

Ivan.

Thank you, Ivan!

Thank you, Ivan. I have been trying for ages to figure out a way to mask a display object using another one dynamically created. Was trying all sorts of ridiculous methods of using display.save and applying the resulting files as masks. This works so much better!

Thank you, Ivan. I have been trying for ages to figure out a way to mask a display object using another one dynamically created. Was trying all sorts of ridiculous methods of using display.save and applying the resulting files as masks. This works so much better!