Jump to content

How do I separate javascript file in order to get better performance for the game?


sinanqd10
 Share

Recommended Posts

Now I have only one javascript file which included many states there.

 

Here is my sample code:

var WelcomeState = {        preload: function () {            game.load.image('bg1', 'games/RockPaperScissors/assets/Game0002.png');                   },        create: function () {            game.add.sprite(0, 0, 'bg1');           },        start: function () {            this.game.state.start('instruct');        }// other methods....};var InstructState = {        preload: function () {            game.load.image('bg2', 'games/RockPaperScissors/assets/Game0001.png');            game.load.image('guide', 'games/RockPaperScissors/assets/Game0015.png');            game.load.spritesheet('readyPlay', 'games/RockPaperScissors/assets/ready.png', 130, 46);        },            readyPlay: function () {            this.game.state.start('rockpaperscissor');        }// other methods....};var game = new Phaser.Game(480, 360, Phaser.AUTO, 'game_container', null, false, false);game.state.add('welcome', WelcomeState);game.state.add('instruct', InstructState);game.state.start('welcome');

Can anyone tell me the best practice way to separate Javascript file in order to get  better performance of the game?

Link to comment
Share on other sites

Separation doesn't really give you performance. Just convience on writing the code. Infact many of us use automated tools to combine and minify the separate files to get smaller file size and less files for browser to download.

 

Good example for simple separation is in Phaser library and it's Grunt file itself.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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