SoPhased Posted July 25, 2017 Report 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); } }; Quote Link to comment Share on other sites More sharing options...
samme Posted July 25, 2017 Report Share Posted July 25, 2017 export default class GameState extends Phaser.State { update () { this.handleJump(); this.handleCollisions(); this.handleInput(); } handleCollisions () {/*…*/} handleInput () {/*…*/} handleJump () {/*…*/} } Quote Link to comment Share on other sites More sharing options...
SoPhased Posted July 25, 2017 Author Report 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. Quote Link to comment Share on other sites More sharing options...
rblopes Posted July 25, 2017 Report 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(); } Quote Link to comment Share on other sites More sharing options...
samme Posted July 26, 2017 Report Share Posted July 26, 2017 What and where is the error? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.