feat: Move paddle redraw to tick method

This commit is contained in:
sigmasternchen 2024-11-03 21:20:07 +01:00
parent d8d6ba0118
commit e51307b79b
2 changed files with 3 additions and 3 deletions

View file

@ -51,6 +51,8 @@ export class Game {
this.handleCollisions(ball); this.handleCollisions(ball);
}); });
this.paddle.redraw();
if (this.running) { if (this.running) {
requestAnimationFrame(this.tick); requestAnimationFrame(this.tick);
} }

View file

@ -22,7 +22,7 @@ export class Paddle {
this.redraw(); this.redraw();
} }
private readonly redraw = (): void => { public readonly redraw = (): void => {
this.element.style.left = this.position + "px"; this.element.style.left = this.position + "px";
this.element.style.width = this.size + "px"; this.element.style.width = this.size + "px";
@ -37,8 +37,6 @@ export class Paddle {
Math.min(fieldWidth - this.size / 2, Math.min(fieldWidth - this.size / 2,
Math.max(this.size / 2, event.offsetX) Math.max(this.size / 2, event.offsetX)
); );
this.redraw();
} }
public readonly setup = (gameElement: HTMLElement, ballLaunchHandler: (ball: Ball) => void): void => { public readonly setup = (gameElement: HTMLElement, ballLaunchHandler: (ball: Ball) => void): void => {