我正在尝试使用函数()4.3.3 kineticjs加载stage.load阶段,但没有使用这样的函数Kinetic.Node.create。我不知道如何使用这个功能,有人可以解释它是如何使用的。非常感谢你
答案 0 :(得分:0)
从JSON创建舞台并不复杂:
var stage = Kinetic.Node.create(myJSON, 'container');
以下是一些示例代码:
// Use jQuery to call to your server and retrieve
// the JSON representation of your KineticJS stage
// jQuery make calling JSON easy, but...
// Alternatively, you can use straight javascript--google ;)
$.ajax({
type: "GET",
dataType: "json",
url: 'http://www.yourSite.com/yourStageInJSON.json',
success: successHandler,
error: errorHandler
});
// this is called when your json-stage has been downloaded
function successHandler(myJSON){
// use the downloaded json to create the stage
// "container" is just the normal KineticJS container div
var stage = Kinetic.Node.create(myJSON, 'container');
}
// this is called if there was a problem with the download
function errorHandler(){
alert("Something has gone horribly wrong--call somebody!");
}
如果你想查看序列化为json的阶段是什么样的,你可以像这样序列化一个现有的阶段:
var json = stage.toJSON();