在您的 main.lua 中,您应该创建一个函数 loadAlImages(),您将在其中加载所有高清图像和精灵表。
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 )
现在,如果您想显示和更新另一个带有百分比的文本,以计算您的下一个屏幕资源已加载多少,您应该使用 .isVisible=false 创建图像、精灵以及它们何时全部加载创建更改 .isVisible=true。
您可以在创建一些图像后添加一些更新百分比文本的代码。
local loadingText = display.newText("LOADING ...", 0, 0, native.systemFont, 24)
myText:setTextColor(255, 255, 255)
local function loadAlImages()
--create some images here.
--update text's percentage to 20%
--create some images here.
--update text's percentage to 50%
--create some sprites here.
--update text's percentage to 90%
--change **.isVisible=true** for all your created files but **.alpha=0**
--update text's percentage to 100%
--remove LOADING text
--transition .alpha of all images to 1
end
timer.performWithDelay( 500, loadAlImages, 1 )
我认为您可以将所有图像文件放在一个显示组中并在该组上设置 .isVisible=false。这将为您节省一些代码行。 .alpha=0
也一样
有很多方法。您可以声明您的变量,然后在 loadAlImages() 函数中创建它们,或者您可以将它们全部放在一个表中并使用该表来获取您想要的图像。
第一个例子:
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
以表格为例:
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
更多信息:
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