Great point, Torben. So, the following code works to create the flattened image, but it takes soooooo long to “invalidate” or perhaps the better word is “render” that it’s impractical (half a second for just 1500 objects). Any ideas on how to speed it up?
lowercase “h” = H*3, which means that our canvas is 3 times the height of the screen
display.setStatusBar(display.HiddenStatusBar) display.setDefault( "anchorX", 0 ) display.setDefault( "anchorY", 0 ) local W=display.contentWidth local H=display.contentHeight local h=H\*3 print("Resolution of Canvas:"..W.." x "..H) math.randomseed( os.time() ) local obj={} --======================================================================================= -- code routines --======================================================================================= local function funcButton(e) -- allow the user to scroll to see the multi-screen high image local obj = e.target -- Key pressed -- if(e.phase == "began") then display.getCurrentStage():setFocus(obj) obj.\_isFocus = true obj.oldX = obj.x obj.oldY = obj.y elseif(e.phase == "moved") then obj.x = obj.oldX + (e.x - e.xStart) obj.y = obj.oldY + (e.y - e.yStart) -- Key released -- elseif(e.phase == "ended" or e.phase == "cancelled") then if obj.\_isFocus then obj.\_isFocus = false display.getCurrentStage():setFocus(nil) end -- if obj.\_isFocus then end -- touch began, moved, ended, cancelled return true end --======================================================================================= local function showMemoryInfo() print("-------------------------") print("Time: "..(system.getTimer()/1000).." seconds") local m=math.floor(collectgarbage("count")) / 1024 --- with / 1024, makes it into MB local t=math.floor(system.getInfo("textureMemoryUsed") / 1024) / 1024 -- into MB local mu=m+t local ttlMem\_str = string.format("total = %.3f MB", mu) local memUsage\_str = string.format("memory usage = %.3f MB", m) local texUsage\_str = string.format("textures = %.3f MB", t) local ts="\n "..memUsage\_str..", "..texUsage\_str..", "..ttlMem\_str if G\_dm~=nil then display.remove(G\_dm) G\_dm=nil end G\_dm=display.newText(ts,0,0,native.systemFont,display.viewableContentHeight\*.025) return ts end --======================================================================================= local function afterInvalidate() print("5: After canvas:invalidate('canvas')"..showMemoryInfo()) for i = 1, #obj do obj[i]:removeSelf() obj[i] = nil end timer.performWithDelay(100, function() print("6: After removal of original objects"..showMemoryInfo()) end) end --======================================================================================= -- 5th version MAIN CODE --======================================================================================= print("1: Before anything:"..showMemoryInfo()) for i=1,150 do obj[i] = display.newText("T",0,0,native.systemFontBold,H\*0.25) obj[i].fill = {math.random(0, 255)/255, math.random(0, 255)/255, math.random(0, 255)/255} obj[i].x=math.random(W)-(W\*.5) obj[i].y=math.random(h)-H end -- now draw an X in the upper-left, upper-right, lower-left and lower-right of the canvas local x=-W\*.5; local y=-h\*.5 obj[#obj+1]=display.newText("X",x,y,native.systemFontBold,H\*0.25) obj[#obj+1]=display.newText("X",x,y+h-obj[#obj].height,native.systemFontBold,H\*0.25) obj[#obj+1]=display.newText("X",x+W-obj[#obj-1].width,y,native.systemFontBold,H\*0.25) obj[#obj+1]=display.newText("X",x+W-obj[#obj-2].width,y+h-obj[#obj-2].height,native.systemFontBold,H\*0.25) print("2: After creating display objects:"..showMemoryInfo()) local canvas = graphics.newTexture( { type="canvas", width=W, height=h} ) local rect = display.newImageRect( canvas.filename, -- "filename" property required canvas.baseDir, -- "baseDir" property required W,h) rect:addEventListener("touch", funcButton) print("3: After creating newTexture:"..showMemoryInfo()) -- Create display object with texture as contents for i = 1, #obj do canvas:draw(obj[i]) end print("4: After drawing objects onto canvas:"..showMemoryInfo()) canvas:invalidate() timer.performWithDelay(100, afterInvalidate) --delay a tiny bit to allow Corona to render