Jump to content

Loading Javascript Files in order


royibernthal
 Share

Recommended Posts

I thought using states did that after you added the initial state inside the index.html in the order necessary.

States use a boot, preload, menu then game.

Maybe look into that and configure from there to your needs. Look in resources/project templates in the src for the state like set up.

Link to comment
Share on other sites

What does loaded asynchronously mean? One after the other?

 

I understood from rich that I had many problems on mobile because I didn't explicitly load my files in order.

 

What does require.js do?

 

Phaser's Loader.script() - is call back called after the script tag is generated or after the script file has been loaded?

Link to comment
Share on other sites

What does loaded asynchronously mean? One after the other?

 

No, the opposite. The browser sends out all requests and inserts the file in the order that they return.

This is normally the order in which they are specified, but it does not have to be.

 

If this happens, your javascript may fail (it runs as if the files were loaded in a different order - so if phaser.js is suddenly at the bottom, nothing will work.)

 

This is why for production releases putting all files into one big file is necessary. 

The file should then be minified, but this is just for bandwidth reasons.

 

This is why you should embrace grunt :) - with a grunfile in the project directory (which takes one minute to setup, if you have done it before) you just type "grunt" into the command line and get a deployable directory within seconds. (clean old release directory, concat all js, minify all js, copy resources, copy js.. done)

Link to comment
Share on other sites

If you develop on a local webserver (or even on the filesystem) the order is almost guaranteed to be correct.

(Only through "the tubes" of the internet it's possible that one file takes longer to fetch then the others below it)

Link to comment
Share on other sites

I'll look into grunt, but isn't there a way to load synchronously? At least for the development phase.

 

I use grunt for my games and find it does help alot. You may like to look at Codevinskys set up for creating a phaser game set up with grunt and many other useful things:

 

http://www.html5gamedevs.com/topic/5127-generator-phaser-official-yeoman-generator-for-phaser-projects/

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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