function refBalls(){
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var circles = [{x:40,y:100,r:20,color:'black',vx:5,vy:10}]
function draw(){
ctx.beginPath();
ctx.arc(circles[0].x, circles[0].y, circles[0].r, 0, 2 * Math.PI);
ctx.fillStyle = "blue";
ctx.fill();
if((circles[0].x + circles[0].r + circles[0].vx > c.width + c.style.left) || (circles[0].x - circles[0].r + circles[0].vx < c.style.left)){
circles[0].vx = -circles[0].vx;
}
circles[0].x += circles[0].vx;
requestAnimationFrame(draw);
}
requestAnimationFrame(draw);}
Ich bin in der Lage zu sehen, den Ball bewegt, aber ich sehe seine vorherige Position. Ich sollte ein Ball bewegt werden sehen, stattdessen bin ich auf der Leinwand einen Streifen wie ein Ball Gemälde zu sehen. Kann mir jemand helfen? this is what I'm seeing in my browserBouncing Bälle zeichnen in einer Leinwand, Javascript
wie die Leinwand löschen? –
im Beispiel gibt es einige weitere Lektüre. aber im Grunde verwendet ctx.clearRect (0, 0, canvas.width, canvas.height); am Anfang Ihres Animationsrahmens – dcbarans