[英]How do I create a Loading screen in Corona SDK?
我的游戲是高清,我使用了很多高清圖像和精靈表,占用了大量的紋理內存。 結果是,在我的場景加載之前,我得到了一個丑陋的黑色屏幕,持續了幾秒鍾。 所以我想制作一個加載屏幕。 其實兩個。 一個用於我的主菜單,一個用於我的主游戲。 我整天搜索了很多,但我沒有找到任何制作加載屏幕的步驟。
我想做的事:
- 有一個加載屏幕,只有一個文本說“加載...”和另一個文本,其中百分比計算我的下一個屏幕資產加載了多少。
- 我完成后,我想刪除我的加載屏幕,並開始我的主菜單場景,或我的主要游戲場景,沒有延遲。
我正在為Android開發,但歡迎任何關於iPhone的評論。
故事板如何知道我的場景跟蹤是否加載以及百分比是多少? 我應該把我的newImageRects放在哪里? 我找不到一個教程。
在你的main.lua中,你應該創建一個函數loadAlImages() ,你將在其中加載所有的高清圖像和spritesheets。
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()函數調用加載圖像。 這將顯示加載屏幕。 調用之后,等待500ms並調用所有其他圖像。 當游戲進入主菜單時,刪除加載屏幕我的意思是:
local loadImg = display.newImageRect( "loading.png" .. blah blah )
timer.performWithDelay( 500, function() -- load all other images then main() end, 1 )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.