Jump to content

Function is undefined


pete796
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

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