Hi guys,
My game needs to load a few TexturePacks, such as
packA = TexturePack.new("virusA/virusA.txt", "virusA/virusA.png",true)
and it can take up to about ~30 seconds on slower phones, so I want to add a "loading..." splash screen to appear during this time.
I tried the most obvious, adding a stage:addChild( bitmap ) before loading the packs, but it does not appear, i.e. the screen is black for 30 seconds and then the game starts.
Please suggest, how do I show a splash screen? Thanks.
Comments
1. First only load your "loading" image or logo and put it on the stage.
2. Wait for 1 enter frame event
3. Load all of your other assets
Likes: RogerT
Likes: RogerT
http://www.nightspade.com
It was all a bit trial and error so there may well be a better/more efficient way of doing it, but this brought up my splash screen OK and then loaded the rest after it has appeared.
Likes: RogerT
Likes: RogerT
http://www.giderosmobile.com/forum/discussion/995/how-can-i-create-preloader
Likes: RogerT
stage:setBackgroundColor( 0.1,0.1,0.1 )
text = TextField.new(nil, "System Scaled")
text:setPosition(150,350)
text:setTextColor(0xffffff)
text:setText("LOADING")
stage:addChild(text)
anim = {}
packArray = {}
local function preloader()
if ( #packArray < 7 ) then
if ( #packArray == nil ) then numLoading = 0
else numLoading = #packArray+1 end
packArray[#packArray+1] = TexturePack.new("ktest.txt", "ktest"..numLoading..".png",true)
text:setText("LOADING "..#packArray)
end
-----------------------------------------------------------------------------------
if ( #packArray == 7 ) then
stage:removeEventListener(Event.ENTER_FRAME, preloader)
for pk=1, #packArray, 1 do
for lp=1,221,1 do
anim[#anim+1] = Bitmap.new(packArray[pk]:getTextureRegion("k ("..lp..").png"))
end
end
frame = 1
stage:addEventListener("enterFrame", onEnterFrame )
end
end
stage:addEventListener(Event.ENTER_FRAME, preloader)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function onEnterFrame()
if ( #anim > 0 ) then
if ( bitMap ~= nil ) then
stage:removeChild(bitMap)
end
frame = frame +1
if ( frame > #anim ) then
frame = 1
end
text:setText("frame: "..frame)
bitMap = anim[frame]
bitMap:setAnchorPoint(0.5,0.5)
bitMap:setPosition(200,200)
stage:addChild( bitMap )
end
end
Likes: RogerT
---------------------------------------