KineticJSを使用して、垂直線と水平線、および中央に円を描画しています。垂直線と円をグループ化しましたが、水平線と一緒に円も移動したいと思います。スクリプトは次のとおりです。
var stage1 = new Kinetic.Stage({
container: 'container',
width: 1024,
height: 1024
});
var blayer1 = new Kinetic.Layer();
var bgroup1 = new Kinetic.Group({
draggable: true,
dragBoundFunc: function (pos) {
return {
x: pos.x,
y: this.getAbsolutePosition().y
}
}
});
var BlueLine1 = new Kinetic.Line({
points: [512, 0, 512, 1024],
stroke: '#0080c0',
strokeWidth: 2,
lineCap: 'round',
lineJoin: 'round'
});
var circle = new Kinetic.Circle({
x: stage1.getWidth() / 2,
y: stage1.getHeight() / 2,
radius: 140,
stroke: '#00ffff',
strokeWidth: 2
});
bgroup1.add(circle);
bgroup1.add(BlueLine1);
blayer1.add(bgroup1);
stage1.add(blayer1);
blayer1.draw();
var glayer1 = new Kinetic.Layer();
var ggroup1 = new Kinetic.Group({
draggable: true,
dragBoundFunc: function (pos) {
return {
x: this.getAbsolutePosition().x,
y: pos.y
}
}
});
var GreenLine1 = new Kinetic.Line({
points: [0, 512, 1024, 512],
stroke: 'red',
strokeWidth: 2,
lineCap: 'round',
lineJoin: 'round'
});
ggroup1.add(GreenLine1);
glayer1.add(ggroup1);
stage1.add(glayer1);
glayer1.draw();
}