Jump to content

I'm new...have a couple of questions


next2heaven
 Share

Recommended Posts

So I'm looking into making my first project and need to use an object oriented approach.  I see that Phaser has State's and that's what I'd use for the various screens.  Here are a couple of questions I have about that approach though:

  1. For this project I'd need to bring in random levels...so I guess States.  I noticed that Phaser has you load in each .js file on the main page.  But if I'm pulling them in dynamically, how would that work?
  2. When I load a state, do they have their own preload functions so it'll preload before showing that state?  I don't necessarily want everything loaded at the beginning of the game because only a 1/10 of all the content will be used in any given play session.
  3. If I can dynamically load these states, can I then unload them?

 

Thanks!

Link to comment
Share on other sites

You don't have to put each state in its own script file. Each state just has to be defined before you add it to the State Manager.

Each state can load its own assets in preload and do its own setup in create.

The State Manager will close down the state automatically when switching. You can do any cleanup in shutdown.

Link to comment
Share on other sites

1) Pulling in code dynamically can, potentially, be tricky, its certainly more complex but, given the new module spec will soon be in all browsers (I think Chrome may have shipped it behind a flag today) this will soon(ish) be the de facto way to go. I'm assuming Phaser can handle registering states after the start of the app, pretty sure it doesn't care, so long as you don't try running one before it exists you could dynamically load JS in later but... dont bother, load it all upfront (preferably concatenating all your files into one and, possibly minifying/obfuscating it for production builds), it'll be much much much easier.

If you're loading data on the fly things are much easier than loading code.

2) aye

3) Generally unnecessary, if you're not using something it'll generally be flagged as unused and the browser will handle cleaning this up for you when it deems best (note that there are numerous things that can stop memory being flagged for removal, and the browser will choose when it thinks is best, your opinion won't necessarily concur). JS runs in a memory managed environment i.e. garbage collected.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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