diff --git a/public/javascripts/game.js b/public/javascripts/game.js index 3f4145b..ce6cbb2 100644 --- a/public/javascripts/game.js +++ b/public/javascripts/game.js @@ -1,6 +1,10 @@ const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); +// Load background image once, outside of any function +const backgroundImage = new Image(); +backgroundImage.src = '/assets/images/background.png'; + let bricks = []; let paddle = { x: 175, y: 510, width: 75, height: 15 }; let ball = { x: 200, y: 370, dx: 4, dy: -4, radius: 8 }; @@ -85,9 +89,7 @@ function update() { ctx.clearRect(0, 0, canvas.width, canvas.height); // Draw background image - let background = new Image(); - background.src = '/assets/images/background.png'; - ctx.drawImage(background, 0, 0, canvas.width, canvas.height); + ctx.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height); // Draw floor line ctx.beginPath();