如何在Corona SDK中创建加载屏幕?



我的游戏是高清的,我使用了很多高清图像和精灵表,占用了很多纹理内存。结果是,在我加载场景之前,我看到了一个难看的黑屏,持续了几秒钟。我想做一个加载屏幕。实际上两种。一个用于我的主菜单,一个用于我的主游戏。我一整天都在搜索,但我没有找到任何制作加载屏幕的步骤。

我想做什么:

-有一个加载屏幕,只有一个文本说"loading…"和另一个文本的百分比,计算我的下一个屏幕资产加载了多少。

-在我完成后,我想要删除加载屏幕并开始我的主菜单场景,或者我的主要游戏场景,没有延迟。

我正在为Android开发,但是任何关于iPhone的评论都是受欢迎的。

故事板如何知道我的场景是否加载以及加载的百分比是多少?我应该把newImageRects放在哪里?我找不到一个教程

你应该创建一个函数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

我假设,在场景中使用它们之前,您预加载了所有图像。

display.newImage()

函数可以做到这一点。下面是你应该做的:

1。对图像不做任何操作,而是使用display.newImage()函数调用正在加载的图像。这将显示一个加载屏幕。调用它之后,等待500毫秒,然后调用所有其他图像。当游戏应该进入主菜单时,移除加载画面我的意思是:

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

最新更新