SoPhased Posted July 25, 2017 Share Posted July 25, 2017 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 More sharing options...
samme Posted July 25, 2017 Share Posted July 25, 2017 export default class GameState extends Phaser.State { update () { this.handleJump(); this.handleCollisions(); this.handleInput(); } handleCollisions () {/*…*/} handleInput () {/*…*/} handleJump () {/*…*/} } Link to comment Share on other sites More sharing options...
SoPhased Posted July 25, 2017 Author Share Posted July 25, 2017 Thats what I have and it doesnt work. Input works fine but both collisions and jump only work when theyre directly in the update function. Link to comment Share on other sites More sharing options...
rblopes Posted July 25, 2017 Share Posted July 25, 2017 What happens if you modify those lines and place handleCollisions() before handleJump() inside your update loop? update () { this.handleCollisions(); // <--- this.handleJump(); this.handleInput(); } Link to comment Share on other sites More sharing options...
samme Posted July 26, 2017 Share Posted July 26, 2017 What and where is the error? Link to comment Share on other sites More sharing options...
Recommended Posts