Phyron Posted May 4, 2015 Share Posted May 4, 2015 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 More sharing options...
ZoomBox Posted May 4, 2015 Share Posted May 4, 2015 If I understand well, you should extend the Sprite class:http://phaser.io/examples/v2/sprites/extending-sprite-demo-2 Once you've extendend the sprite class to create a new class "Monster" that has it's own abilities, you'll be able to create a "Monster" and it'll act the way you want Link to comment Share on other sites More sharing options...
MichaelD Posted May 4, 2015 Share Posted May 4, 2015 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 More sharing options...
Recommended Posts