Skip to content

Commit b3bacb0

Browse files
Update game.js
1 parent c5a30c3 commit b3bacb0

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

js/game.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,30 +145,24 @@ class Game {
145145
this.player.x + this.player.width/2,
146146
this.player.y + this.player.height
147147
);
148-
149-
// Draw player with radiosity effect
150-
this.ctx.save();
151-
152-
// Draw base sprite
148+
149+
// Draw player with radiosity effect applied directly on the player's image
150+
// Create an offscreen canvas to tint the image
151+
const offCanvas = document.createElement('canvas');
152+
offCanvas.width = this.player.img.width;
153+
offCanvas.height = this.player.img.height;
154+
const offCtx = offCanvas.getContext('2d');
155+
offCtx.drawImage(this.player.img, 0, 0);
156+
offCtx.globalCompositeOperation = 'source-atop';
157+
offCtx.fillStyle = `rgba(${bgColor.r}, ${bgColor.g}, ${bgColor.b}, 0.33)`;
158+
offCtx.fillRect(0, 0, offCanvas.width, offCanvas.height);
153159
this.ctx.drawImage(
154-
this.player.img,
160+
offCanvas,
155161
this.player.x,
156162
this.player.y,
157163
this.player.width,
158164
this.player.height
159165
);
160-
161-
// Apply color influence using source-atop to respect transparency
162-
this.ctx.globalCompositeOperation = 'source-atop';
163-
this.ctx.fillStyle = `rgba(${bgColor.r}, ${bgColor.g}, ${bgColor.b}, 0.6)`;
164-
this.ctx.fillRect(
165-
this.player.x,
166-
this.player.y,
167-
this.player.width,
168-
this.player.height
169-
);
170-
171-
this.ctx.restore();
172166
}
173167

174168
// 4. Draw effects

0 commit comments

Comments
 (0)