How to create a boot screen in the Corona SDK?

My game is High Definition, and I use a lot of HD images and sprites, taking up a lot of texture memory. As a result, I get an ugly black screen before loading Scene, spanning several seconds. Therefore, I want to make a loading screen. Actually two. One for my main menu and one for my main game. I searched a lot all day, but I did not find any steps to create a loading screen.

What I want to do:

. It has a loading screen with the text "LOADING ..." and other text with a percentage that calculates how many of my next screen resources are loaded.

-After I finished, I want to remove the loading screen and start the main menu scene or my main game scene without delay.

I am developing for Android, but any comments for the iPhone are also welcome.

How does the scanning system know if the next scene is loaded and what percentage? Where should I put my newImageRects? I could not find a single textbook.

+6
source share
2 answers

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

+7
source

I assume that you preload all the images before using them in the scene.

 display.newImage() 
Function

will do it. So here is what you should do:

1. Nothing with images, but call the boot image using the display.newImage () function. A download screen will appear on the screen. After that, wait 500 ms and call up all the other images. When the game should go to the main menu, clear the loading screen. I mean:

 local loadImg = display.newImageRect( "loading.png" .. blah blah ) timer.performWithDelay( 500, function() -- load all other images then main() end, 1 ) 
+1
source

Source: https://habr.com/ru/post/946216/


All Articles