In your main.lua, you must create the loadAlImages () function, where you load all your HD images and sprites.
local loadingText = display.newText("LOADING ...", 0, 0, native.systemFont, 24) myText:setTextColor(255, 255, 255) local function loadAlImages() --create all your images here. --remove LOADING text end --if you still see black screen at the start try to increase delay > 500 ms timer.performWithDelay( 500, loadAlImages, 1 )
Now, if you want to show and update another text with a percentage that calculates how many downloads of your next screen resources, you have to create your images, sprites with .isVisible = false and when they are all created change .isVisible = true . You can put some code that updates the percentage text after creating some images.
local loadingText = display.newText("LOADING ...", 0, 0, native.systemFont, 24) myText:setTextColor(255, 255, 255) local function loadAlImages() --create some images here. --update text percentage to 20% --create some images here. --update text percentage to 50% --create some sprites here. --update text percentage to 90% --change **.isVisible=true** for all your created files but **.alpha=0** --update text percentage to 100% --remove LOADING text --transition .alpha of all images to 1 end timer.performWithDelay( 500, loadAlImages, 1 )
I think you can put all your image files in one display group and set .isVisible = false in this group. This will save you a few lines of code. The same for α = 0
There are many ways. You can declare your variables and then create them in the loadAlImages () function, or you can put them all in a table and use this table to get the image you want. First example:
local image local function loadAlImages() --create some images here. image = display.newImageRect( "image.png", 100, 100 ) image:setReferencePoint( display.CenterReferencePoint ) image.x = display.contentCenterX image.y = display.contentCenterY --create some sprites here. end
An example with the following table:
local imagesTable = { } local function loadAlImages() --create some images here. local image = display.newImageRect( "image.png", 100, 100 ) image:setReferencePoint( display.CenterReferencePoint ) image.x = display.contentCenterX image.y = display.contentCenterY imagesTable.image = image --create some sprites here. end
Additional Information:
http://lua-users.org/wiki/ScopeTutorial
http://www.coronalabs.com/blog/2011/06/21/understanding-lua-tables-in-corona-sdk/
http://lua-users.org/wiki/TablesTutorial