3
\$\begingroup\$

I'm a first time user of Phaser, been trying to make a simple point and click type game. I'm trying to keep things very modular, so I'm defining a list of levels (states) in a JSON, and then every level has its own JSON containing the objects within that level.

However, I'm encountering an issue in that, when changing states, I get a black flash while the assets for the next state load (this happens whether I iterate through the JSON list or define everything manually). From what I've read, all sprites should be loaded in the preload stage, however, by doing this I'm causing that tiny but noticeable black pause.

I know one way would be to simply load every asset at the start of the game, but that seems incredibly inefficient (wouldn't that fill up the memory immensely?). I would rather load a state's assets from the "parent" state. However, in my quick test (which maybe I did wrong) it seems that game.load doesn't work properly if done within the create stage? What is the best approach to doing this?

\$\endgroup\$
6
\$\begingroup\$

What you're doing is multi-part loading assets, which is extremely common and a very sensible approach. You cannot avoid the 'pause' or black screen though, because the assets have to come down the wire at some point, right?

So all you can do is make this process as attractive and seamless as possible. Either a nice preloader, or maybe showing the next part of a story as the assets load? At this stage it's a more conceptual issue than a technical one.

You absolutely can load assets outside of a preload function, and there's an example showing how to do it here: http://examples.phaser.io/_site/view_full.html?d=loader&f=load+events.js&t=load%20events

But you've still got to cater for what happens during this process, no matter when it's started.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ What about loading assets of third level during second level and so on \$\endgroup\$ – Pooya Estakhri Feb 27 '15 at 11:55
  • \$\begingroup\$ Yes that's an option, but it depends on the game. Pulling assets down the wire on mobile devices eats up quite a bit of CPU - especially if it's audio that needs decoding. So pull something down at the wrong time and you could stall your game entirely for a second or two, which is less than ideal. \$\endgroup\$ – PhotonStorm Feb 27 '15 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.