Skip to content

Instantly share code, notes, and snippets.

@rhysburnie
Last active December 16, 2015 01:19
Show Gist options
  • Save rhysburnie/5354424 to your computer and use it in GitHub Desktop.
Save rhysburnie/5354424 to your computer and use it in GitHub Desktop.
makeShapeComposite function for Kineticjs
/**
* makeShapeComposite function on a gloabl namespace - see var namespace
*
* ns.kineticSupport.makeShapeComposite(shape, operation);
* @param Kinetic.Shape (family)
* @param Sting - valid globalCompositeOperation name
* @return the supplied shape after globalCompositeOperation set
*/
(function(){
var namespace = 'myns',
ns = window[namespace] = (window[namespace] || {});
ns.kineticSupport || (ns.kineticSupport={});
ns.kineticSupport.makeShapeComposite = function(shape, operation) {
shape.attrs._drawFunc = shape.attrs.drawFunc;
shape.attrs.drawFunc = function (kineticShape) {
kineticShape.context.save();
kineticShape.context.globalCompositeOperation = operation;
this.attrs._drawFunc.call(this, kineticShape);
kineticShape.context.restore();
};
return shape;
};
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment