【发布时间】:2021-12-31 03:49:08
【问题描述】:
我正在尝试为从一个位置到另一个位置的移动圆圈设置动画。在下面的示例中,它是从 (10, 10) 到 (50, 50) 下面是我的 Bullet 类的代码。当用户单击空间时,我会创建一个新的 Bullet 对象并尝试对其进行动画处理。如何制作流畅的动画?
class Bullet{
constructor(x, y){
this.x = x;
this.y = y;
this.size = 10;
}
draw(){
ctx.fillStyle = "green";
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, 2 * Math.PI)
ctx.fill();
}
fire(locationX, locationY){
}
}
document.addEventListener('keydown', function(e){
if(e.key == ' '){
var currBullet = new Bullet(10, 10);
currBullet.fire(50, 50);
}
});
function reset(){
ctx.clearRect(0, 0, w, h);
}
【问题讨论】:
标签: javascript animation html5-canvas