OK I tried out my idea and it works.
The only issue is how long you have to wait for the validation to take effect - in theory it is the next draw pass, but I had to insert a delay of 300 milliseconds between each update to actually have it kick in (or else it returned a blank texture).
Here’s my code.
Every 300 milliseconds it creates 100 random lines, swaps the two snapshot objects, then clears all the lines.
The end result is it keeps filling up and filling up with lines overlaid.
Just copy and paste the following code into a fresh main.lua (no other files needed) and run it (on the iphone simulator for ‘fullscreen’, heh - can always just set the width and height to whatever device you prefer simulating on).
[lua]-- Set up status bar
display.setStatusBar( display.HiddenStatusBar )
– Set up ----------------------------------------------------
local width = 320
local height = 480
local snapshots = {
active = display.newSnapshot( width, height ),
storage = display.newSnapshot( width, height ),
}
local drawGroup = display.newGroup()
local group = drawGroup.parent
for k, v in pairs( snapshots ) do
v.anchorX = 0
v.anchorY = 0
end
group:insert( snapshots.active )
snapshots.active.x, snapshots.active.y = 0, 0
– Place the storage group into the active group
snapshots.active:insert( snapshots.storage )
snapshots.storage.x, snapshots.storage.y = -width / 2, -height / 2
– Place the draw group into the active group
snapshots.active:insert( drawGroup )
drawGroup.x, drawGroup.y = -width / 2, -height / 2
– Run event -------------------------------------------------
local function drawLines()
for i = 1, 100 do
local line = display.newLine( drawGroup, math.random( 0, width ), math.random( 0, height ), math.random( 0, width ), math.random( 0, height ) )
line.strokeWidth = math.random( 1, 10 )
line:setStrokeColor( math.random( 0, 255 ) / 255, math.random( 0, 255 ) / 255, math.random( 0, 255 ) / 255 )
end
end
local function toggleGroups()
– Swap snapshots
snapshots.active, snapshots.storage = snapshots.storage, snapshots.active
– Kill the draw group (and hence everything in it) and recreate it
drawGroup:removeSelf()
drawGroup = display.newGroup()
– Place the active group into the group
group:insert( snapshots.active )
snapshots.active.x, snapshots.active.y = 0, 0
– Place the storage group into the active group
snapshots.active:insert( snapshots.storage )
snapshots.storage.x, snapshots.storage.y = -width / 2, -height / 2
– Place the draw group into the active group
snapshots.active:insert( drawGroup )
drawGroup.x, drawGroup.y = -width / 2, -height / 2
– Draw more lines
drawLines()
– Update
snapshots.active:invalidate()
end
– Repeat 10000 times
timer.performWithDelay( 300, toggleGroups, 10000 )
[/lua]