W swojej main.lua należy utworzyć funkcję loadAlImages() gdzie można załadować wszystkie obrazy HD i 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)
Teraz, jeśli chcesz pokazać i zaktualizować kolejny tekst z odsetek, który oblicza, ile Kolejne aktywa ekran załadowaniu należy tworzyć obrazy, duszki z .isVisible = false i kiedy są wszystkie utworzone zmiany .isVisible = true. Możesz wstawić kod aktualizujący tekst procentowy po utworzeniu niektórych obrazów.
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)
myślę, że można umieścić wszystkie swoje pliki obrazów w jednym grupy wyświetlacza i ustawić .isVisible = false na tej grupie. Pozwoli to zaoszczędzić trochę linii kodu. To samo dla .alpha = 0
Istnieje wiele sposobów. Możesz zadeklarować swoje zmienne, a następnie utworzyć je w funkcji loadAlImages() lub możesz umieścić je wszystkie w tabeli i użyć tej tabeli, aby uzyskać pożądany obraz. Pierwszy przykład:
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
Przykład z tabeli:
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
Więcej informacji:
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
Czy wszystkie obrazy i duszki powinny być lokalne? czy globalny? Bo chcę użyć niektórych z nich z wydarzeniem "dotknij", aby dodać funkcjonalność. – user2347313
Dziękuję bardzo! głosowałem – user2347313