Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How to show a spash-screen while my game is loading? — Gideros Forum

How to show a spash-screen while my game is loading?

RogerTRogerT Member
edited February 2013 in General questions
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

  • talistalis Guru
    Accepted Answer
    ifound this answer by atilim. i didn't tried by myself but should work.

    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

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks, by the way, how can I "Wait for 1 enter frame event" ?
  • NascodeNascode Guru
    Accepted Answer
    @RogerT you could use timer or using enterframe event, in which you track frames manually

    Likes: RogerT

    have fun with our games~
    http://www.nightspade.com
    +1 -1 (+1 / -0 )Share on Facebook
  • petecpetec Member
    Accepted Answer
    @RogerT - I used atilim's method. I renamed what had been main.lua to main2.lua and found that I needed to exclude it from execution so that it didn't run (right click on main2.lua and select exclude). I then added the following code as a new main.lua:
    local splashScreen=Bitmap.new(Texture.new("splashScreen.jpg"),true)
    stage:addChild(splashScreen)
     
    local frameCount=0
    local function loadRest()
    	if frameCount==1 then
    		stage:removeEventListener(Event.ENTER_FRAME,loadRest)
    		require("main2")
    	end
    	frameCount=frameCount+1
    end
     
    stage:addEventListener(Event.ENTER_FRAME,loadRest)
    where the require("main2") bit runs main2.lua.

    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

    +1 -1 (+1 / -0 )Share on Facebook
  • yvz5yvz5 Member
    Accepted Answer
    if you use screen manager, first load loading.lua and then try to go load the main script. in that way it would show only loading screen before you load your main file.

    Likes: RogerT

    +1 -1 (+1 / -0 )Share on Facebook
  • THanks guys, seems to work! :)
  • By the way, maybe it is possible to somehow count the progress of loading data, to show it to the user?...
  • thanks, got it working based on atilim's example. here's my code:

    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

    +1 -1 (+1 / -0 )Share on Facebook
  • CyberienceCyberience Member
    edited March 2013
    I use the time event like this, cause I need to load the Database. the 1 is to run once only, I could make it run many times if I want, and remember there is an Event for its completion you can use too. I made it anonymous, but you could just call your function if you want. This is also my Whole main.lua file. :)
    local background = Bitmap.new(Texture.new("images/back/loading.jpg"))
    stage:addChild(background)
    DB = DBclass.new("db/Top100.db3")
     
    local authormenu = Timer.new(1000, 1)  --[[Delay execution]]
    authormenu:addEventListener(Event.TIMER, 
     	function(event)
    		stage:addChild(Menu.new())
    		stage:removeChild(background)
    	end
     )
    authormenu:start()
    REAL programmers type copy con filename.exe
    ---------------------------------------
Sign In or Register to comment.