0

一定時間後にスポーン(アクティブになる)したいゲームオブジェクトがあります。時間が経過するたびに、次のエラーが発生します。

Uncaught TypeError: Object [object global] has no method 'SpawnCounter'

私が間違っていることがわかりませんか?これは私のオブジェクトの一部です:

this.Update = function(){
    //Collisions
    if(this.active){
        if(player.Intersects(this)){
            console.debug("Player Touching Pick Up!");
            if(this.type == "weapon")
                player.weapon = this.subtype;
            this.active = false;
        }
    }
    else{
        //THIS IS THE TIMER
        setTimeout( function(){ this.SpawnCounter(); }, 2000 );
    }
};

this.SpawnCounter = function(){
    this.active = true;
};

これはすべて、ゲームのピックアップであり、2秒後に再び表示されます。

4

1 に答える 1

0

たぶん、これを別の変数にスコープしてみてください...

this.Update = function(){
    var that = this;
    //Collisions
    if(this.active){
        if(player.Intersects(this)){
            console.debug("Player Touching Pick Up!");
            if(this.type == "weapon")
                player.weapon = this.subtype;
            this.active = false;
        }
    } else{
        //THIS IS THE TIMER
        setTimeout( function(){ that.SpawnCounter(); }, 2000 );
    }
};

this.SpawnCounter = function(){
    this.active = true;
};
于 2013-02-27T21:58:50.467 に答える