OK. That explains why I was getting these temporary hangs after implementing G2.0 every time I started an app.
I didn’t want to modify all the image loading in every module within my apps, so to solve this problem (I hope temporarily) I created a small module with overridden functions that force a load.
-- -- override.lua -- local saved = {}; saved.newImage = display.newImage; display.newImage = function(...) local forceLoad = saved.newImage(select(1, ...)); forceLoad.width, forceLoad.height = 0.1, 0.1; timer.performWithDelay(100, function() forceLoad:removeSelf(); end); local img = saved.newImage(select(1, ...)); return img; end saved.newImageRect = display.newImageRect; display.newImageRect = function(...) local forceLoad = saved.newImageRect(select(1, ...)); forceLoad.width, forceLoad.height = 0.1, 0.1; timer.performWithDelay(100, function() forceLoad:removeSelf(); end); local img = saved.newImageRect(select(1, ...)); return img; end
The only thing that needs to done after this is to put require(“override”) at the top of main.lua.
I tested this on some projects and it seems to work well. The initial lag I saw was gone.
It’s not pretty, but it’s functional…
To take Bryan’s sample app it would become:
-- -- main.lua -- require("override") local imageToLoad = "boxer-1920.jpg" local background = display.newImage( imageToLoad, display.contentCenterX, display.contentCenterY ) background.alpha = 0 -- Without the "override" step the image in background isn't loaded until it becomes visible local myText = display.newText( "Moving text!", 0,0, native.systemFont, 40 ) myText:setFillColor( 1, 255/255, 255/255 ) transition.to( myText, { time=10000, x=320, y=480 } ) local function test() background.alpha = 1 background.x = 0 end timer.performWithDelay( 5000, test)