1 decade ago by lTyl
Hello Impact community,
I am having difficulty getting context.globalCompositeOperations working when drawing directly to the canvas. I am creating a simple non-dynamic lighting system where the lights and shadows are only calculated once when the level is first loaded. I am trying to do this by using the 'lighter' composite operation and then a 'source-over' operation for the darkmask.
Here is the light rendering code I have now:
The dark mask is drawn on top of the canvas, but it basically blocks out everything else, and the 'lighter' operation is all but ignored. What I believe should happen is the light object should pierce through the dark mask, but instead the dark mask is completely blocking the light.
Am I going about this the wrong way?
Thanks.
I am having difficulty getting context.globalCompositeOperations working when drawing directly to the canvas. I am creating a simple non-dynamic lighting system where the lights and shadows are only calculated once when the level is first loaded. I am trying to do this by using the 'lighter' composite operation and then a 'source-over' operation for the darkmask.
Here is the light rendering code I have now:
for(var i= 0; i<this.lights.length; i++){ ig.system.context.save(); ig.system.context.globalCompositeOperation = "lighter"; this.lights[i].draw(ig.system.context); ig.system.context.globalCompositeOperation = "source-over"; this.darkMask.draw(ig.system.context); ig.system.context.restore(); }
The dark mask is drawn on top of the canvas, but it basically blocks out everything else, and the 'lighter' operation is all but ignored. What I believe should happen is the light object should pierce through the dark mask, but instead the dark mask is completely blocking the light.
Am I going about this the wrong way?
Thanks.