Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Function is undefined


Recommended Posts


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.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() {

SuperSmash.Player.prototype.groundState = function() {

Link to comment
Share on other sites


  • Recently Browsing   0 members

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