CHANNELS:

All
chris posted 2 years ago

Try something like this:

let animationId
function annimation() {
    ctx.clearRect(0, 0, canvas.width, canvas.height)
    tableStyle();
    animationId = requestAnimationFrame(annimation);
    ball.update();
    racketLeft.draw();
    racketRight.draw();

    if (score === 21) cancelAnimationFrame(animationId)
}
annimation();

This'll stop your animation whenever score is equal to 21, just make sure you have score declared somewhere.

0
C
ChristianZube posted 2 years ago

Thank you for your reply. It has worked.

1

Want to participate?

Create a free Chris Courses account to begin

or
Sign In

Providing the lift to launch your development career

© 2024 Chris Courses. All rights reserved.