shadow logic is now applied to buffer context, not a newly created one each time drawScene is created

This commit is contained in:
Eric Rowell 2013-09-26 22:10:37 -07:00
parent 4cf15cedb8
commit ba6e30aa97
2 changed files with 23 additions and 23 deletions

View File

@ -104,12 +104,14 @@
* element is the y component
*/
intersects: function() {
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments));
var stage = this.getStage();
var hitCanvas = stage.hitCanvas;
hitCanvas.getContext().clear();
this.drawScene(hitCanvas);
var p = hitCanvas.context.getImageData(pos.x | 0, pos.y | 0, 1, 1).data;
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
stage = this.getStage(),
bufferHitCanvas = stage.bufferHitCanvas,
p;
bufferHitCanvas.getContext().clear();
this.drawScene(bufferHitCanvas);
p = bufferHitCanvas.context.getImageData(pos.x | 0, pos.y | 0, 1, 1).data;
return p[3] > 0;
},
/**
@ -213,29 +215,27 @@
context = canvas.getContext(),
drawFunc = this.getDrawFunc(),
applyShadow = this.hasShadow() && this.getShadowEnabled(),
stage, tempCanvas, tempContext;
stage, bufferCanvas, bufferContext;
if(drawFunc && this.isVisible()) {
if (applyShadow) {
stage = this.getStage();
tempCanvas = new Kinetic.SceneCanvas({
width: stage.getWidth(),
height: stage.getHeight()
});
tempContext = tempCanvas.getContext();
tempContext.save();
tempContext._applyLineJoin(this);
tempContext._applyAncestorTransforms(this);
drawFunc.call(this, tempContext);
tempContext.restore();
bufferCanvas = stage.bufferCanvas;
bufferContext = bufferCanvas.getContext();
bufferContext.clear();
bufferContext.save();
bufferContext._applyLineJoin(this);
bufferContext._applyAncestorTransforms(this);
drawFunc.call(this, bufferContext);
bufferContext.restore();
context.save();
context.save();
context._applyShadow(this);
context.drawImage(tempCanvas._canvas, 0, 0);
context.drawImage(bufferCanvas._canvas, 0, 0);
context.restore();
context._applyOpacity(this);
context.drawImage(tempCanvas._canvas, 0, 0);
context.drawImage(bufferCanvas._canvas, 0, 0);
context.restore();
}
else {

View File

@ -300,10 +300,10 @@
this.content.style.width = width + PX;
this.content.style.height = height + PX;
this.bufferCanvas.setSize(width, height, 1);
this.hitCanvas.setSize(width, height);
this.bufferCanvas.setSize(width, height);
this.bufferHitCanvas.setSize(width, height);
// set pointer defined layer dimensions
// set layer dimensions
for(n = 0; n < len; n++) {
layer = layers[n];
layer.getCanvas().setSize(width, height);
@ -646,7 +646,7 @@
container.appendChild(this.content);
this.bufferCanvas = new Kinetic.SceneCanvas();
this.hitCanvas = new Kinetic.HitCanvas();
this.bufferHitCanvas = new Kinetic.HitCanvas();
this._resizeDOM();
},