In kineticjs, is it possible to save complex shapes to json and restore it? -
i can't seem to work. know can built in shape functions such circle, polygon complex shapes, can still serialize if @ json string, don't see x,y coordinate. jsfiddle.net/q7g99/1/. serialize , de-serialize don't give errors nothing appear on canvas.
the "primitive" shapes (kinetic.rect, kinetic.circle, etc) use properties define shapes.
the kinetic.shape uses context drawing commands define shape.
properties can serialized -- drawing commands cannot.
that's why kinetic.shape not serialize.
as workaround, save scenefunc function in .js file that's loaded page.
eg. in myshapescenefuncs.js:
// scenefunc code var shape1=new kinetic.shape function shape1scenefunc(context) { context.beginpath(); context.moveto(200, 50); context.lineto(420, 80); context.quadraticcurveto(300, 100, 260, 170); context.closepath(); // kineticjs specific context method context.fillstrokeshape(this); } // rewire scenefunc shape1 shape1.scenefunc(shape1scenefunc);
Comments
Post a Comment