これは跳ねるボールのキャンバス アニメーションです。http://jsfiddle.net/eakA4/
私の問題は、ボールが軌跡を残すこと、つまりボールが過去にあった場所を示す線を残すことです。
ボールの位置を決定するコードは次のとおりです。
(function drawFrame () {
window.requestAnimationFrame(drawFrame, canvas);
context.clearRect(0, 0, canvas.width, canvas.height);
//theta = Math.atan2(mouse.y-ball.y,mouse.x-ball.x);
ball.x += vx;
ball.y += vy;
if (ball.x > canvas.width - ball.radius) {
ball.x = canvas.width - ball.radius;
vx *= -1;
} else if (ball.x < 0 + ball.radius){
ball.x = 0 + ball.radius
vx *= -1;
}
if (ball.y > canvas.height - ball.radius){
ball.y = canvas.height - ball.radius
vy *= -1;
} else if (ball.y < 0 + ball.radius){
ball.y = 0 + ball.radius;
vy *= -1;
}
ball.draw(context);
}());
私の問題は、clearRect() を使用しているため、描画しようとするパスがすべて消去されていることです。私ができることは、ball.x と ball.y の座標を配列に追加し続け、キャンバスの lineTo() を使用してこれらすべてのポイントをフレームごとにリンクすることですが、それは非常に迅速に多数のポイントに到達します。
誰でもこれを行う方法を提案できますか?