我只是对setinterval()
的一个小小的讨论答案 0 :(得分:0)
@luctowers:这是答案
class Renderer {
constructor(canvas) {
this.ctx = canvas.getContext("2d");
}
resize() {
this.ctx.canvas.width = window.innerWidth;
this.ctx.canvas.height = window.innerHeight;
}
}
class Game {
constructor(canvas, fps) {
this.gfx = new Renderer(canvas);
this.fps = fps;
}
start() {
this.intervalID = setInterval(() => this.update, 1000 / this.fps)
}
update() {
this.gfx.resize(); // error undefined
//to do
}
}
试一试!