I’m struggling with applying a blur effect on a snapshot. I’ve got a multiple moving items that are inserted into a snapshot. Blur is applied to it and then gets updated at each frame so that those items can be seen moving.
But here’s the issue: as soon as I invalidate the snapshot, it ignores the horizontal blur and only applies the vertical one.
Here’s a simplified code so you can reproduce it:
-- Loading the image
image = display.newRect(0,0,50,50)
-- Creating the snapshot
snapshot = display.newSnapshot(display.contentWidth, display.contentHeight)
snapshot.group:insert(image)
-- Applying the blurGaussion effect
snapshot.fill.effect = "filter.blurGaussian"
-- Unblur transition
local testA, testB
function unblur()
print("unblur")
snapshot.transitionA = transition.to(snapshot.fill.effect.horizontal, {time=2500, blurSize=8, sigma=8, onComplete=blur})
snapshot.transitionB = transition.to(snapshot.fill.effect.vertical, {time=2500, blurSize=8, sigma=8})
end
-- Blur transition
function blur()
print("blur")
snapshot.transitionA = transition.to(snapshot.fill.effect.horizontal, {time=2500, blurSize=128, sigma=512, onComplete=unblur})
snapshot.transitionB = transition.to(snapshot.fill.effect.vertical, {time=2500, blurSize=128, sigma=512})
end
-- Starts the blur/unblur loop transition
blur()
-- invalidate
function invalidateSnapshot()
print("invalidateSnapshot() - h : " .. math.floor(snapshot.fill.effect.horizontal.blurSize) .. " - " .. math.floor(snapshot.fill.effect.horizontal.sigma) .. " - v : " .. math.floor(snapshot.fill.effect.vertical.blurSize) .. " - " .. math.floor(snapshot.fill.effect.vertical.sigma))
snapshot:invalidate()
end
Runtime:addEventListener("enterFrame",invalidateSnapshot)
If the line “snapshot:invalidate()” is disabled, horizontal and vertical visual blur are properly applied. Once it’s enabled, only the vertical visual blur seems to be applied.