Jump to content

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


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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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