Jump to content

Functions outside update dont work


SoPhased
 Share

Recommended Posts

When I try to move certain functions out of the update function they stop working. 

Below is my state class and the functions.

 

I have a class:

export default class Game extends Phaser.State {

  constructor() {
    super();

  }

}

Works:

update() {
  this.game.physics.arcade.collide(this.player, this.obstacles); // handleCollision()
  if (this.keys.up.isDown) {                                     // handleJump()
    this.player.jump();
  }

Doesnt work:

update() {
  this.handleJump()
  this.handleCollisions();
  this.handleInput();
}

However, this works:

handleInput() {

  if (this.keys.left.isDown) { 
    this.player.move(-1);
  } else if (this.keys.right.isDown) { 
    this.player.move(1);
  } else { 
    this.player.move(0);
  }
};
Link to comment
Share on other sites

export default class GameState extends Phaser.State {

  update () {
    this.handleJump();
    this.handleCollisions();
    this.handleInput();
  }

  handleCollisions () {/*…*/}

  handleInput () {/*…*/}

  handleJump () {/*…*/}

}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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