1

Как в этом случае сохранить контекст и избежать ошибок при первом и повторном вызове window.requestAnimationFrame ?

'use strict';
class Game{
    constructor(context){
        this.context = context;
        this.gameUpdate;
        this.updatePerSecond = 10;
    }

    initiate(){
        this.gameUpdate = setInterval(this.update, 1000 / this.updatePerSecond);
        window.requestAnimationFrame(this.draw);
    }

    update(){
    }

    draw(){
        window.requestAnimationFrame(this.draw);
    }
}
var game = new Game('123');
game.initiate();
Nick
  • 11

0 Answers0