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

View File

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