-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapshots.lua
32 lines (30 loc) · 909 Bytes
/
snapshots.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
local originalNewSnapshot = display.newSnapshot
local snapshotsStore = {}
display.newSnapshot = function( w, h )
local snapshot = originalNewSnapshot( w, h )
snapshotsStore[ #snapshotsStore + 1 ] = snapshot
return snapshot
end
local onSystemEvent = function( event )
if event.type == "applicationResume" then
local removes = {}
for i,snapshot in pairs(snapshotsStore) do
if snapshot and snapshot.invalidate then
snapshot:invalidate()
elseif not snapshot or not snapshot.invalidate then
removes[#removes+1] = i
end
end
for i=#removes,1,-1 do
local s = removes[i]
if snapshotsStore[s] then
if snapshotsStore[s].removeSelf then
snapshotsStore[s]:removeSelf()
end
snapshotsStore[s] = nil
end
table.remove(snapshotsStore,s)
end
end
end
Runtime:addEventListener( "system", onSystemEvent )