Jump to content

Organize code


Phyron
 Share

Recommended Posts

Hi!

 

If use this code for example (using the states):

 

BasicGame.Game = function (game) {this.monster;this.monsterVel = 10;};BasicGame.Game.prototype = {create: function () {this.monster =  this.game.add.sprite(this.game.width/2,this.game.height/2,"monster");},update: function () {this.monster.x += this.monsterVel;}};

How to separate a monster in other file and after use here? I need have monster variables, create,and update in other file and include here, and I can acces the monster object in this file.

Link to comment
Share on other sites

If you create a file for example "monster.js" and include it in your html file and then do: 

var monster = monster || {};monster = {   var monster1 = "";   createMonster:function(){},   updateMonster:function(){},   getMonster: function(){return monster1;}};

All in all there are many ways to do that but it boils down to this: "if you include a .js file in your html you have access to this file contents (in js) from all files".

 

But I would encourage you to read a bit about js structure and coding techniques.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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