Jump to content

Update function doesn't work in file in Phaser


weratius
 Share

Recommended Posts

I have a game with structure like this.

(Some lines of code were deleted. Also all file are required by Browserify)

Game needs boot.js and play.js

game.js:

w = window.innerWidth * window.devicePixelRatio,h = window.innerHeight * window.devicePixelRatio;window.game = new Phaser.Game((h > w) ? h : w, (h > w) ? w : h, Phaser.CANVAS, 'Phaser', {render:render});game.state.add('Boot', require('./states/boot.js'));game.state.add('Play', require('./states/play.js')); 

boot.js starts play.js

In boot.js:

module.exports = {      preload: function() {      //...    },    create: function() {      game.physics.startSystem(Phaser.Physics.ARCADE);      game.world.setBounds(0, 0, 6000, 6000);      this.game.state.start("Play");    }  };

play.js requires interfacePanels.js

In play.js:

chat = require('./../chat.js');interfacePanels = require('./../interfacePanels.js');module.exports = {    create: function() {       interfacePanels.init();    },    update: function() {      //....    }};

There is a method that shows profile of a player in interfacePanels.js (also this file requires profile.js)

 

And here is the problem file profile.js:

module.exports = {   initialized: false,   START_X: '',   START_Y: '',   create: function() {      //... some code   },   update: function() {      console.log('profile')   },};

And so, update function doesn't work at all

I wonder but if I add update function in play.js file there will be a lot if console.log commands

Please, I need help)

I need this to move elements to starts points and check whether overLap happens or not

Thank you in advance!!!

Link to comment
Share on other sites

Why should profile.js' update method get called every frame? If your play.js state isn't calling anything in interfacePanels in its update method, and interfacePanels doesn't then call profile.js... then that's probably why it's broken.

Link to comment
Share on other sites

Why should profile.js' update method get called every frame? If your play.js state isn't calling anything in interfacePanels in its update method, and interfacePanels doesn't then call profile.js... then that's probably why it's broken.

But why just I can't call update method in profile.js ? I need this due to the variables I have there. It will be easier and etc.

 

Is it possible?

Link to comment
Share on other sites

Again, I'm not seeing enough code here. Sure, you could do this:

// In play.js...var profile = require('./profile');module.exports = {   // other state functions...   update: function() {      profile.update();   }};

In your code examples, nothing in play.js is calling anything in profile.js. That's why your update method isn't working. Unless I'm missing something?

Link to comment
Share on other sites

Again, I'm not seeing enough code here. Sure, you could do this:

// In play.js...var profile = require('./profile');module.exports = {   // other state functions...   update: function() {      profile.update();   }};

In your code examples, nothing in play.js is calling anything in profile.js. That's why your update method isn't working. Unless I'm missing something?

Oh my God... I even didn't think about it, so foolish)) 

Thank you =)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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