Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Creating a spash screen that works with scene manager? — Gideros Forum

Creating a spash screen that works with scene manager?

Tom2012Tom2012 Guru
edited October 2012 in General questions
Hey gang, I'm looking for a way to have a 'loading' splash screen - simliar to the Gideros one that appears on non-subscriber apps.

As the player enters a level, I'd like to show 'loading' while the texture file loads.

I've read through this thread from May: http://www.giderosmobile.com/forum/discussion/995/how-can-i-create-preloader

But can't figure out how to use it with Scenemanager, where my assets vary from scene to scene.

Is this the way to do it?

main.lua
--define scenes
sceneManager = SceneManager.new({
["Menu"] = menu,
["Credits"] = credits,
["Help"] = help,
["Level 1"] = level1
})
 
application:setBackgroundColor(0x000000)
 
--add manager to stage
stage:addChild(sceneManager);
 
sceneManager:changeScene("Level 1", 1);
Level 1.lua
level1 = Core.class(Sprite)
function level1:init()
 
local loading = Bitmap.new(Texture.new("gfx/loading.png"))
self:addChild(loading)
 
local function preloader()
 
-- load all your assets here
 
local Atlas2 = TexturePack.new("Atlases/Atlas 2.txt", "Atlases/Atlas 2.png");
 
self:removeChild(loading)
loading = nil;
self:removeEventListener(Event.ENTER_FRAME, preloader)
 
-- rest of code here
 
end
end
+1 -1 (+3 / -0 )Share on Facebook

Comments

  • I know this is an old thread, but this is exactly what I'm looking for as well :(
  • jdbcjdbc Member
    edited October 2015
    Use this code in your main.lua replacing with your own splash image
     
    application:setKeepAwake(true)
     
    local function draw_loading()
    	loading = Sprite.new()
     
    	local logo = Bitmap.new(Texture.new("gfx/jdbc_games.png", true))
    	logo:setY(150)
    	loading:addChild(logo)	
     
    	stage:addChild(loading)
    end
     
    local function preloader()
     
    	stage:removeEventListener(Event.ENTER_FRAME, preloader)
     
    	-- Load all your assets here
     
    	-- Game starting
    	scenes = {"game"}
     
    	sceneManager = SceneManager.new({
    		["game"] = GameScene,
    		})
     
    	stage:addChild(sceneManager)
     
    	local currentScene = scenes[1]
     
    	local timer = Timer.new(1000, 1)
    	timer:addEventListener(Event.TIMER, 
    				function()
    					-- Remove loading scene
    					stage:removeChild(loading)
    					loading = nil
    					sceneManager:changeScene(currentScene)
    				end)
    	timer:start()
    end
     
    draw_loading()
    stage:addEventListener(Event.ENTER_FRAME, preloader)
  • Hi @jdbc

    Thanks for the reply!

    I think your example only works when you're loading all the assets at the start.

    I'm trying to load assets in different scenes and show a loading screen without interruptions to fade in/out.

    Is there any way to do this?

    Thank again guys!
  • Hi @jdbc

    Thanks for the reply!

    I think your example only works when you're loading all the assets at the start.

    I'm trying to load assets in different scenes and show a loading screen without interruptions to fade in/out.

    Is there any way to do this?

    Thank again guys!
    Just create a loading scene and then change to your game scene:
    LoadingScene = Core.class(Sprite)
     
    function LoadingScene:init()
     
      -- Load your assets here
     
      self:addEventListener("enterEnd", self.enterEnd, self)
    end
     
    -- When scene is loaded
    function LoadingScene:enterEnd()
      sceneManager:changeScene(scenes[1], 1, SceneManager.flipWithFade, easing.linear)
    end
  • Ideally Giderso will eventually get an optional splash screen that will be user defined. This would load immediatly whilst the rest of the program is initialised (lua, etc). It could turn off at the first draw instance.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • NinjadoodleNinjadoodle Member
    edited October 2015
    Thanks guys for the replies!

    I think that a user defined 'level to level' pre-loader (with progress bar) would be brilliant.

    Is this sort of feature on the roadmap?

  • I don't know about that. I was thinking something that would be displayed as quickly as possible and would stay for a couple of seconds or until the first draw by the main lua code.

    Likes: GiderosFan

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
  • Yes an Splash Screen option would be very nice or an Sample Project in the Gideros Project Folder (Splash Screen with Progressbar). I think an Splash is the Fundamental of every Game.

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • Sorry guys, I get what you're talking about :) My feature request belongs in another thread haha
  • Continuing on a old thread here... :-)

    When my 'game' is starting on a 2013 device, there's a black screen for a number of seconds before entering the main scene (not main.lua). What's happening during that black screen? I think it is loading all assets at that point (there's a great many textures and sound files) (but I'm not sure).

    I'm thinking especially of this point in the code snippets above:
               -- Load all your assets here
    Maybe I'm missing out something very fundamental here, but how can I decide when to load all those assets at that point?

    I've tried the enter frame event solution in both main.lua and init.lua, but it seems to do nothing, when the system runs through that code the assets seem to have been already loaded. Or am I getting it wrong?
  • @sayes there is a feature in the latest build that allows you to do tasks like load things in the background. I haven;t tried this myself yet but it sounds like the kind of thing you might look at implementing to alleviate your blocked app issue.

    Have a read of http://docs.giderosmobile.com/reference/gideros/Core/asyncCall and checkout the AsyncTextureLoading example in the latest build.
    +1 -1 (+5 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    edited August 2016
    @saeys With the new fake threads (asyncCall) you can start a loader, things start when your main lua code runs out of lines. So make that as short as possible and put everything into your loader and game loop functions. This starts straight away now, there used to be black for a second or two...

    Likes: saeys, plicatibu

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+2 / -0 )Share on Facebook
  • Thanks @antix & @SinisterSoft Now, I'm trying to understand how to use asyncCall to make a splash screen while all assets are loading. I have played around with the assyncCall example a little. I have a couple of questions, but I start with one... :P
    With the new fake threads (asyncCall) you can start a loader, things start when your main lua code runs out of lines.
    Ok, my last line (in my own project) is a SceneManager changeScene() method, so it starts to execute things before main.lua is out of lines. How do I prevent that?

  • Put the change scene at the end of the fake thread.

    Likes: antix, saeys

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+2 / -0 )Share on Facebook
  • Stupid problem, simple answer... :\"> I'm still on my learning curve. Thanks for helping unknotting things!

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.