Typscript variable this.rightDown is always false in updateGame method

Im having a hard time working how how this (this.rightDown ) value is always false in the update method

class Game {
    rightDown: bool = false;

 onKeyDown(evt) {
        if (evt.keyCode == 39) this.rightDown = true;
        else if (evt.keyCode == 37) this.leftDown = true;
        if (evt.keyCode == 32) {
            this.space = true;
            var bullet = new GameObjects.GameObjects.Bullet(10);
            this.addProjectile(bullet);
        };
    }

    onKeyUp(evt) {
        if (evt.keyCode == 39) this.rightDown = false;
        if (evt.keyCode == 37) this.leftDown = false;
        if (evt.keyCode == 32) this.space = false;
    }


    update(elapsed: number) {
     
        if (this.rightDown) {

            this.player.xVelocity = 1;
            this.player.x += this.player.xVelocity * elapsedUnit;
        }

}
}

  $(document).ready(function () {
        var game = new Game();
        $(document).keydown(game.onKeyDown);
        $(document).keyup(game.onKeyUp);
        var timeA = new Date().getTime();
        setInterval(function () {
            var timeB = new Date().getTime();
            var elapsedTime = timeB – timeA;
            game.update(elapsedTime);
            game.draw();
        }, 1000 / this.FPS);
    });

Leave a Reply