ロードjson Kinetics 4.3.3 - kineticjs

私はステージをロードしようとしています。()4.3.3 kineticjsを持つロードステージですが、このような関数は使用されません。Kinetic.Node.create。私はこの機能をどのように使用するのか分からず、誰かがどのように使用されているかを説明することができます。どうもありがとうございました

回答:

回答№1は0

JSONからステージを作成するのは複雑ではありません:

  1. シリアル化されたjsonステージをダウンロードしてください。
  2. ステージを水分補給する 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();