在kineticjs中,是否可以将复杂形状保存到json并将其还原?

在kineticjs中,是否可以将复杂形状保存到json并将其还原?,json,kineticjs,Json,Kineticjs,我似乎无法让它发挥作用。我知道你可以使用内置的形状函数,比如圆形、多边形,但是对于复杂的形状,它仍然可以序列化,但是如果你看json字符串,你看不到x,y坐标。jsfiddle.net/Q7G99/1/。序列化和反序列化不会给出任何错误,但画布上不会显示任何内容。基本形状(dynamic.Rect、dynamic.Circle等)使用属性定义其形状 Shape使用上下文绘图命令来定义形状 属性可以序列化--绘图命令不能序列化 这就是为什么Kinetic.Shape不能完全序列化 作为一种解决方法

我似乎无法让它发挥作用。我知道你可以使用内置的形状函数,比如圆形、多边形,但是对于复杂的形状,它仍然可以序列化,但是如果你看json字符串,你看不到x,y坐标。jsfiddle.net/Q7G99/1/。序列化和反序列化不会给出任何错误,但画布上不会显示任何内容。

基本形状(dynamic.Rect、dynamic.Circle等)使用属性定义其形状

Shape使用上下文绘图命令来定义形状

属性可以序列化--绘图命令不能序列化

这就是为什么Kinetic.Shape不能完全序列化

作为一种解决方法,将sceneFunc函数保存在与页面一起加载的.js文件中

例如,在myShapeSceneFuncs.js中:

// this is the sceneFunc code from 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 back into shape1

shape1.sceneFunc(Shape1SceneFunc);
“基本”形状(dynamic.Rect、dynamic.Circle等)使用属性定义其形状

Shape使用上下文绘图命令来定义形状

属性可以序列化--绘图命令不能序列化

这就是为什么Kinetic.Shape不能完全序列化

作为一种解决方法,将sceneFunc函数保存在与页面一起加载的.js文件中

例如,在myShapeSceneFuncs.js中:

// this is the sceneFunc code from 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 back into shape1

shape1.sceneFunc(Shape1SceneFunc);
“基本”形状(dynamic.Rect、dynamic.Circle等)使用属性定义其形状

Shape使用上下文绘图命令来定义形状

属性可以序列化--绘图命令不能序列化

这就是为什么Kinetic.Shape不能完全序列化

作为一种解决方法,将sceneFunc函数保存在与页面一起加载的.js文件中

例如,在myShapeSceneFuncs.js中:

// this is the sceneFunc code from 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 back into shape1

shape1.sceneFunc(Shape1SceneFunc);
“基本”形状(dynamic.Rect、dynamic.Circle等)使用属性定义其形状

Shape使用上下文绘图命令来定义形状

属性可以序列化--绘图命令不能序列化

这就是为什么Kinetic.Shape不能完全序列化

作为一种解决方法,将sceneFunc函数保存在与页面一起加载的.js文件中

例如,在myShapeSceneFuncs.js中:

// this is the sceneFunc code from 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 back into shape1

shape1.sceneFunc(Shape1SceneFunc);