CHANNELS:

All
C
ChristianZube posted 2 months ago
chris posted 2 months 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 a month 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

© 2022 Chris Courses. All rights reserved.