Javascript 调用requestanimationframe时增加x和y
我希望x和y在每个requestAnimationFrame中增加1,它只增加一次Javascript 调用requestanimationframe时增加x和y,javascript,html5-canvas,Javascript,Html5 Canvas,我希望x和y在每个requestAnimationFrame中增加1,它只增加一次 您的animate函数正在通过每次update调用启动行构造函数。 尝试在显示构造函数上启动行类,如下所示: constructor() { this.canvas = document.querySelector("#canvas"); this.ctx = this.canvas.getContext("2d"); this.width = window.innerWidth;
您的
animate
函数正在通过每次update
调用启动行
构造函数。
尝试在显示
构造函数上启动行
类,如下所示:
constructor() {
this.canvas = document.querySelector("#canvas");
this.ctx = this.canvas.getContext("2d");
this.width = window.innerWidth;
this.height = window.innerHeight;
this.canvas.width = this.width;
this.canvas.height = this.height;
this.animateBound = this.animate.bind(this);
this.line = new Line();
}
在更新
函数中,调用现有的行
的实例:
animate() {
this.line.update(this.ctx);
console.log('Animate called');
requestAnimationFrame(this.animateBound);
}
animate() {
this.line.update(this.ctx);
console.log('Animate called');
requestAnimationFrame(this.animateBound);
}