1

ゲーム内に次のサークルがあります。プレーヤーはそれらをゲーム内の別の場所にドラッグします。プレーヤーが選択したときに、もう一度再生すると、形状が init 関数で指定された元の位置に戻ります。これについてどうすればよいですか?ありがとうございました。

stage = new Kinetic.Stage({
   container: "container",
   width: 900,
   height: 550
});

shapes = new Kinetic.Layer();

function init() {
  circle1 = new Kinetic.Circle({
     x: stage.getWidth() / 3.2,
     y: stage.getHeight() / 3.2,
     radius: radius,
     fill: "blue",
     stroke: "black",
     strokeWidth: 4,
     name: "circle",
     draggable: true
});  

shapes.add(circle1)
stage.add(shapes)
4

3 に答える 3

2

次のような非常に便利な setAttrs メソッドを使用することもできます。

circle1.setAttrs(settings);

乾杯!

于 2012-05-25T03:04:18.567 に答える
2

デフォルトを別の変数に保存し、それを使用.setPosition( x, y )してリセットします。

//store settings
var settings = {
     x: stage.getWidth() / 3.2,
     y: stage.getHeight() / 3.2,
     radius: radius,
     fill: "blue",
     stroke: "black",
     strokeWidth: 4,
     name: "circle",
     draggable: true
}; 

//use settings
circle1 = new Kinetic.Circle(settings);

//after move, reset using:
circle1.setPosition(settings.x,settings.y);
于 2012-05-24T19:16:58.260 に答える