From e51307b79bd4aed1dffb34e10fe99cb43ad2a058 Mon Sep 17 00:00:00 2001 From: sigmasternchen Date: Sun, 3 Nov 2024 21:20:07 +0100 Subject: [PATCH] feat: Move paddle redraw to tick method --- src/game/Game.ts | 2 ++ src/game/Paddle.ts | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game/Game.ts b/src/game/Game.ts index dfb65ac..8ab1737 100644 --- a/src/game/Game.ts +++ b/src/game/Game.ts @@ -51,6 +51,8 @@ export class Game { this.handleCollisions(ball); }); + this.paddle.redraw(); + if (this.running) { requestAnimationFrame(this.tick); } diff --git a/src/game/Paddle.ts b/src/game/Paddle.ts index 98b938a..b07f678 100644 --- a/src/game/Paddle.ts +++ b/src/game/Paddle.ts @@ -22,7 +22,7 @@ export class Paddle { this.redraw(); } - private readonly redraw = (): void => { + public readonly redraw = (): void => { this.element.style.left = this.position + "px"; this.element.style.width = this.size + "px"; @@ -37,8 +37,6 @@ export class Paddle { Math.min(fieldWidth - this.size / 2, Math.max(this.size / 2, event.offsetX) ); - - this.redraw(); } public readonly setup = (gameElement: HTMLElement, ballLaunchHandler: (ball: Ball) => void): void => {