Been running into an issue with nested snapshots which I’d greatly appreciate help with.
The basic setup is:
Snapshot 1 contains two groups (group 1 and group 2). In game, the purpose of this snapshot is to frame buffer the entire game scene for post processing.
The lower group (group 1) contains Snapshot 2 (which would be a ground-level FX layer in game), and the upper group (group 2) contains objects.
The code invalidates both snapshots each frame to update them.
However calling invalidate on Snapshot 2 also causes some of the objects from group 2 to not be rendered, which doesn’t make sense. Confusingly, if the position in the group stack of the Snapshot and Objects are swapped so that snapshot 2 is on top, everything is rendered correctly.
Is this a Corona bug? I’ve coded a minimal sample project to reproduce the issue.
Thanks - Sean
– Begin sample code
– parameters
_H = display.contentHeight; _W = display.contentWidth;
display.setStatusBar(display.HiddenStatusBar)
– Snapshot 1
local ss1 = display.newSnapshot(_W, _H)
– Make snapshot coordinates correspond to real screen coordinates so that it properly fills screen
– and drawing to the snapshot is the same as drawing to real screen coords
ss1.anchorX = 0; ss1.anchorY = 0
ss1.group.x = -0.5 * _W; ss1.group.y = -0.5 * _H
local grp1 = display.newGroup()
ss1.group:insert(grp1)
local grp2 = display.newGroup()
ss1.group:insert(grp2)
– Blue background
local ss1_rect = display.newRect(0.5 * _W, 0.5 * _H, _W, _H)
grp1:insert(ss1_rect)
ss1_rect:setFillColor (0, 0, 0.5)
– Grid of objects
for i=1, 9 do
for j=1, 9 do
local object = display.newRect(i/10 * _W, j/10 * _H, 20, 20)
grp2:insert(object)
end
end
– Snapshot 2
local ss2 = display.newSnapshot(_W, _H)
grp1:insert(ss2)
ss2.anchorX = 0; ss2.anchorY = 0
ss2.group.x = -0.5 * _W; ss2.group.y = -0.5 * _H
– Green background
local ss2_rect = display.newRect(0.5 * _W, 0.5 * _H, _W, _H)
ss2.group:insert(ss2_rect)
ss2_rect:setFillColor (0, 0.5, 0, 0.5)
function onFrame()
ss2:invalidate() – Comment this out and the grid of squares reappears
ss1:invalidate()
end
Runtime:addEventListener(‘enterFrame’, onFrame)
– End sample code