javascript - Kinetic js 5.1 globalCompositeOperation how to -
i'm new kinetic js. im trying .globalcompositeoperation work in 2 parts of project have, have tried several solutions can find here, using 'drawfunc', , 'scenefunc', etc... far no luck.
one part of project im trying 'destination-out' work on kinetic.sprite:
var strokessprite = new kinetic.sprite({ image: e, animation: 'intro', animations: { 'intro': config.spritestrokes.frames }, framerate: 7, frameindex: 0, scenefunc: function (ctx) { ctx.save(); ctx.globalcompositeoperation = 'destination-out'; ctx.restore(); } var strokes = new kinetic.layer({ width: 1280, height: 1280, x: stage.getwidth() / 2, y: stage.getheight() / 2, offset: { x: 1280 / 2, y: 1280 / 2 } }); strokes.add(backgroundpainted); strokes.add(strokessprite); strokes.draw(); stage.add(strokes);
"backgroundpainted" kinetic.image
unfortunately here sprite layer being animated on top of 'backgroundpainted', no composite operation being applied :(.
for 2nd instance have, similar, have 2 layers, both shapes inside, added stage. im applying same 'scenefunc' layer on top, , drawing them then. layers both display, no composition being applied. :(
any pointers on should at? see example 'drawfunc' has been changed 'scenefunc' recently, , maybe else has changed, ive tried pretty examples can find here on stack.
thanks
kineticjs not support globalcompositeoperation
.
kineticjs gives wrapper around html5 canvas context, wrapper subset of context not include context.globalcompositeoperation property.
a workaround
you can create canvas element (without appending page). compositing on offscreen canvas. present canvas inside kineticjs, create kinetic.image image property pointing offscreen canvas:
var myoffscreencanvas=document.createelement("canvas"); ... compositing ... // kinetic.image display myoffscreencanvas var mycompositedimage = new kinetic.image({ image:myoffscreencanvas, ... });
Comments
Post a Comment