pete796 Posted January 18, 2017 Share Posted January 18, 2017 Hello, I'm creating, a player object with different states, e.g: onground, inair, etc I'm trying to assign a method to this.currentState. In the update loop, i'm calling this.currentState to run the assigned method (this.groundState), However, i'm receiving the following error 'this.currentState is not a function' SuperSmash.Player = function(game, x, y) { Phaser.Sprite.call(this, game, x, y, 'player'); this.game.physics.arcade.enable(this); this.speed = 500; this.airSpeed = 300; this.jumpPower = 400; this.inAir = true; this.hitGround = false; this.body.gravity.y = 1350; this.currentState = this.groundState; console.log(this.currentState); // undefined }; SuperSmash.Player.prototype = Object.create(Phaser.Sprite.prototype); SuperSmash.Player.prototype.constructor = SuperSmash.Player; SuperSmash.Player.prototype.update = function() { this.currentState(); }; SuperSmash.Player.prototype.groundState = function() { console.log('ground'); } }; Link to comment Share on other sites More sharing options...
phreaknation Posted January 18, 2017 Share Posted January 18, 2017 The update function and groundState may not have the same context. I am pretty sure that update in phaser has the context sent to it. Should console.log(this) in both statements and see what is the context of this is Link to comment Share on other sites More sharing options...
Recommended Posts