Very nice.
Tell me what I'm doing wrong here:
LightDemo = ig.Game.extend({
bg: new ig.Image( 'media/coffee.png' ),
light: null,
ltx: null,
radius: 20,
shadow: null,
stx: null,
init: function() {
ig.input.initMouse();
this.radius *= ig.system.scale;
//light
this.light = ig.$new('canvas');
this.light.width = ig.system.canvas.width;
this.light.height = ig.system.canvas.height;
this.ltx = this.light.getContext('2d');
//shadow
this.shadow = ig.$new('canvas');
this.shadow.width = ig.system.canvas.width;
this.shadow.height = ig.system.canvas.height;
this.stx = this.shadow.getContext('2d');
},
draw: function() {
ig.system.clear( this.clearColor );
this.ltx.clearRect( 0, 0, this.light.width, this.light.height );
this.stx.clearRect( 0, 0, this.shadow.width, this.shadow.height );
this.stx.fillStyle = 'rgba( 0, 0, 0, 0.6 )';
this.stx.fillRect( 0, 0, this.shadow.width, this.shadow.height );
this.stx.globalCompositeOperation = 'source-out';
this.ltx.fillStyle = 'rgba( 255, 255, 255, 0.1 )';
this.ltx.beginPath();
this.ltx.arc( ig.system.getDrawPos( ig.input.mouse.x ),
ig.system.getDrawPos( ig.input.mouse.y ),
this.radius,
0,
Math.PI * 2 );
this.ltx.fill();
this.stx.fillStyle = 'rgba( 255, 255, 255, 0.1 )';
this.stx.beginPath();
this.stx.arc( ig.system.getDrawPos( ig.input.mouse.x ),
ig.system.getDrawPos( ig.input.mouse.y ),
this.radius,
0,
Math.PI * 2 );
this.stx.fill();
ig.system.context.drawImage( this.light, 0, 0, this.light.width, this.light.height );
this.bg.draw( 0, 0 );
ig.system.context.drawImage( this.shadow, 0, 0, this.shadow.width, this.shadow.height );
}
});
This is the draw() in main.js.
this.bg
is a .png that covers the entire canvas. You'll notice that I'm drawing the light layer prior to the bg image, followed by the shadow layer (as noted in your instructions), but I can't reproduce your results.