0

How can that small box under the circle move right or left using those buttons without clearing the ball and upperbox

Canvas game https://code.sololearn.com/WKF6POXXc205/?ref=app

1st Jul 2022, 7:48 PM
Patrick agbenyo paul
Patrick agbenyo paul - avatar
3 odpowiedzi
0
Before drawing a pad reflecting the ball in a new place, you need to remove it from the old place, for this you need to use the clearRect() method before changing the x coordinate, indicating the size of this site: function drawRectangle(direction) { ctx.clearRect(x, y, 50, 5); //debug if(direction == "left"){ x-=10; } else if(direction == "right"){ x+=10; } //ctx.clearRect(0, 0, 109, 198); bug ctx.beginPath(); ctx.rect(x, y, 50, 5); ctx.fillStyle ='blue'; ctx.fill(); ctx.closePath(); }
1st Jul 2022, 9:15 PM
Solo
Solo - avatar
0
Bad tried
2nd Jul 2022, 3:53 PM
Solo
Solo - avatar
- 1
I treid it already it still doesn't work
2nd Jul 2022, 3:58 AM
Patrick agbenyo paul
Patrick agbenyo paul - avatar