MTE and Snapshots?

I’m attempting to blur the map using Snapshots and some code posted to the forums (thanks to Ingemar), so that when a user presses a button to bring up a menu it blurs the map in the background:

[lua]

local addBlurEffect = function(grp, blur)

local innerSnapshot = display.newSnapshot(grp.width+blur/2, grp.height+blur/2);

innerSnapshot.canvas:insert(grp);

innerSnapshot.canvasMode = “discard”;

innerSnapshot.fill.effect = “filter.blurGaussian”;

innerSnapshot.fill.effect.horizontal.blurSize = blur;

innerSnapshot.fill.effect.vertical.blurSize = blur;

innerSnapshot:invalidate(“canvas”);

local outerSnapshot = display.newSnapshot(innerSnapshot.width, innerSnapshot.height);

outerSnapshot.canvas:insert(innerSnapshot);

outerSnapshot.canvasMode = “discard”;

outerSnapshot:invalidate(“canvas”);

return outerSnapshot;

end

local blurryGroup = addBlurEffect(grp, 300);
blurryGroup:translate(display.contentCenterX, display.contentCenterY);

[/lua]

I’m using what’s returned from mte.getMapObj() as the first argument for addBlurEffect, however because this code inserts the MTE group into the snapshot it causes an issue when mte:update() is called presumably because the group has been moved/inserted into another.

mte.lua:13281: attempt to compare nil with number

[lua]

if displayGroups[i].alpha <= 0 and displayGroups[i].isVisible then

[/lua]

Is anybody aware of a solution or an alternative method of achieving this effect? TBH I haven’t had the time to check out G2.0 fully yet, and was just having 20 minutes to experiment so I could be doing this completely wrong.

Many thanks…

For some reason that formatting isn’t very nice - so here’s a link to the original code by Ingemar:

http://forums.coronalabs.com/topic/42000-effect-aplied-to-the-entire-group/

When canvasMode = “discard”, the children added to the snapshot are destroyed when you call innerSnapshot:invalidate(“canvas”), so basically the code is deleting the entire map table. This is not particularly conducive to MTE’s operation!

I was able to come up with a way to make the engine function while inside a snapshot, the code for which is below, but I couldn’t come up with a way to extract the map group back out of the snapshot. It seems once an object is added to a snapshot, that snapshot owns it FOREVER. Someone please correct me if I’m wrong! Of course there’s no reason (other than potentially severe performance constraints) why you couldn’t just leave it inside a snapshot and remove the blur effect when you’re done with it.

local addBlurEffect = function(grp, blur) local innerSnapshot = display.newSnapshot(display.viewableContentWidth \* 2, display.viewableContentHeight \* 2); innerSnapshot.group:insert(grp) innerSnapshot.fill.effect = "filter.blurGaussian"; innerSnapshot.fill.effect.horizontal.blurSize = blur; innerSnapshot.fill.effect.vertical.blurSize = blur; innerSnapshot:invalidate(); return innerSnapshot end

You will also have to call blurryGroup:invalidate() in your enterFrame event.

If you just want a blurred static image to display, I recommend using display.captureScreen and then blurring the returned display object.

When canvasMode = “discard”, the children added to the snapshot are destroyed when you call innerSnapshot:invalidate(“canvas”), so basically the code is deleting the entire map table. This is not particularly conducive to MTE’s operation!

I was able to come up with a way to make the engine function while inside a snapshot, the code for which is below, but I couldn’t come up with a way to extract the map group back out of the snapshot. It seems once an object is added to a snapshot, that snapshot owns it FOREVER. Someone please correct me if I’m wrong! Of course there’s no reason (other than potentially severe performance constraints) why you couldn’t just leave it inside a snapshot and remove the blur effect when you’re done with it.

local addBlurEffect = function(grp, blur) local innerSnapshot = display.newSnapshot(display.viewableContentWidth \* 2, display.viewableContentHeight \* 2); innerSnapshot.group:insert(grp) innerSnapshot.fill.effect = "filter.blurGaussian"; innerSnapshot.fill.effect.horizontal.blurSize = blur; innerSnapshot.fill.effect.vertical.blurSize = blur; innerSnapshot:invalidate(); return innerSnapshot end

You will also have to call blurryGroup:invalidate() in your enterFrame event.

If you just want a blurred static image to display, I recommend using display.captureScreen and then blurring the returned display object.