I'm writing one of those simple games to learn JS and I'm learning HTML5 in the process so I need to draw things on canvas.
Here's the code:
 let paddle = new Paddle(GAME_WIDTH,GAME_HEIGHT);
 new InputHandler(paddle);
 let lastTime = 0;
 const ball = new Image();
 ball.src = 'assets/ball.png';
 function gameLoop(timeStamp){
   let dt = timeStamp - lastTime;
   lastTime = timeStamp;
   ctx.clearRect(0,0,600,600);
   paddle.update(dt);
   paddle.draw(ctx);
   ball.onload = () => {
    ctx.drawImage(ball,20,20);
  }
  window.requestAnimationFrame(gameLoop);
 }
gameLoop();
screenshot: no ball before comment
now I comment out the clearRect():
hello ball.
There's also a paddle at the bottom of the canvas that doesn't seem to be affected by the clearRect() method. It works just fine. What am I missing here?
 
    