Éviter de redessiner le background à chaque fois
This commit is contained in:
parent
13c233daab
commit
bb95f8f8fd
1 changed files with 5 additions and 3 deletions
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue