我正在努力完成理论上简单的事情..
我有一个舞台......如果舞台是空的,点击舞台会在舞台上放置一个带有圆形对象的图层......(我有一个工作代码......)
如果舞台上已经存在图层和对象,我想将它们移动到 x 和 y 位置..
我不清楚销毁对象并创建一个新对象是否更好,或者我可以设置 X 和 Y 并重绘...
我都试过了,但我没有得到正确的东西..
// I have a working code here that detects mouseX and mouseY position
// Detecting if object exists ( works fine )
var theSpot = stage.find('.click_spot');
if ( theSpot[0] === undefined ) {
//alert('Object not found, create a new one...');
var layer = new Kinetic.Layer();
var circle = new Kinetic.Circle({
x: mouseX,
y: mouseY,
radius: 30,
fill: 'red',
stroke: 'black',
strokeWidth: 1,
draggable: true,
name:'click_spot'
});
layer.add(circle);
stage.add(layer);
} else {
// Move the object OR remove and draw a new one
// when I try to remove,, circle.remove(); does not remove it
//alert('Object found, move it to new x, y location');
circle.setX(mouseX); // I tried inserting values directly as well
circle.setY(mouseY); // circle.setX(15) and circle.setX(15) but no joy...
layer.draw();
}