绘制圆球匀速下落时每一次的速度比上一次更快,越来越快,不知道问题出在哪里。求解,谢谢各位了。var canvas = document.getElementById('canvas');var context = canvas.getContext('2d');var ball ={ x:0, y:0, r:15, vy:12, vx:12}var drawCircle = function (x,y,r,color){ context.clearRect(0,0,canvas.width,canvas.height); context.lineWidth = '5'; context.beginPath(); context.arc(x,y,r,0,Math.PI*2,false); context.strokeStyle = 'rgba(120,150,170,0.5)'; context.fillStyle = color; context.closePath(); context.stroke(); context.fill();}var update = function (){ ball.y +=ball.vy; if (ball.y >= canvas.height - ball.r) { ball.y = canvas.height - ball.r; ball.x -= ball.vx; }}this.onclick = function (event){ ball.x = event.clientX; ball.y = event.clientY; setInterval(function () { drawCircle(ball.x,ball.y,ball.r,'blue'); update(); },100);}
添加回答
举报
0/150
提交
取消