Jump to content

Loading Bar NOT for Preload()


ilackarms
 Share

Recommended Posts

I have a very slow create() method on my game state (after all preloading of assets is done in another state). This is because I'm adding a large number of sprites and images to the game.

I would like to display a progress bar and loading graphic when long in-game processing take place (e.g. during create or traveling between game regions). Is this possible? The only examples I can find have to do with setPreloadSprite and onLoad, which only have to do with asset loading and are specific to the preload function.

It looks like I can't do anything with regards to on-screen rendering while create() is running, so my load screen never actually appears until all loading is actually finished.

Link to comment
Share on other sites

I don't believe you can do it the exact way you're wanting to, your long create function is all happening on the same thread, causing the game to hang while it runs. The reason the load screen can have the progress update is that it's loading assets in other threads (the browser is loading the assets, not javascript or phaser) and reporting progress back to the javascript thread.

Javascript is single threaded so you'll have to run your loads over multiple frames. You could fake it by using setTimeout(this.initNext, 0) or similar so that you only initialize one thing per frame (or as many things you can load without hanging too much/makes progress look the way you want). You'd have to keep track of the amount of loading chunks you have and update your progress bar as you load those chunks.

 

Makes sense?

Link to comment
Share on other sites

If your game really takes a long time to load (>10 seconds) you could always divide your sprites into 'groups' to load. Then, instead of a loading bar, you could have a text.

 

ex: there are 150 trees, 50 cars, 45 squirrels to load

change a text only 4 times, saying stuff like 'loading cars', 'loading squirrels', 'loading trees'

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...