File tree Expand file tree Collapse file tree 1 file changed +12
-18
lines changed Expand file tree Collapse file tree 1 file changed +12
-18
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments