Создание сцены из JSON не является сложным:
- Скачать сериализированную этап JS.
- Сода сцена с
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();
предоставьте образец кода – janex