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 回答