Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Phaser javaScript游戏框架,函数未定义_Javascript_Html_Phaser Framework - Fatal编程技术网

Phaser javaScript游戏框架,函数未定义

Phaser javaScript游戏框架,函数未定义,javascript,html,phaser-framework,Javascript,Html,Phaser Framework,我正在使用phaser Javascript框架制作一个简单的游戏。我的玩家对象被分配了不同的状态,例如:onground,inair,等等 我正在尝试为此.currentState分配一个方法。在更新循环中,我调用this.currentState来运行分配的方法(this.groundState) 但是,我收到以下错误信息: 'this.currentState不是函数' 有人能帮忙吗 SuperSmash.Player = function(game, x, y) { Phaser

我正在使用phaser Javascript框架制作一个简单的游戏。我的玩家对象被分配了不同的状态,例如:
onground
inair
,等等

我正在尝试为此.currentState分配一个方法。在更新循环中,我调用
this.currentState
来运行分配的方法(
this.groundState

但是,我收到以下错误信息:

'this.currentState不是函数'

有人能帮忙吗

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.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');
};

我无法重现这个问题。如果我运行与您发布的代码完全相同的代码,那么函数就在那里,我甚至可以调用它。您如何调用构造函数?顺便说一句,它应该是
console.log(this.currentState())