我是 Javascript 和 Kinetics 的新手,我需要实现一个函数来使用 Kinetics.Js 绘制手绘线。我找到了这个示例,但仅适用于开始和端点。我将通过鼠标指针实时绘制...我不知道如何更改功能或推送一些新坐标...
你有想法吗?
var moving = false;
function createLine() {
line = new Kinetic.Line({
points: [0, 0, 0, 0],
stroke: "red",
strokeWidth: 2,
id: 'line',
name: 'line',
draggable: true
});
lineLayer.add(line);
addHoverEffect(lineLayer, line);
lineLayer.draw();
}
function drawLine() {
stage.on("mousedown touchstart", function () {
createLine();
if (moving) {
moving = false;
lineLayer.draw();
} else {
var pos = stage.getPointerPosition();
//start point and end point are the same
line.getPoints()[0].x = parseInt(pos.x);
line.getPoints()[0].y = parseInt(pos.y);
line.getPoints()[1].x = parseInt(pos.x);
line.getPoints()[1].y = parseInt(pos.y);
moving = true;
lineLayer.drawScene();
}
});
stage.on("mousemove touchmove", function () {
if (moving) {
var pos = stage.getPointerPosition();
line.getPoints()[1].x = parseInt(pos.x);
line.getPoints()[1].y = parseInt(pos.y);
moving = true;
lineLayer.drawScene();
}
});
stage.on("mouseup touchend", function () {
moving = false;
removeLineDrawEvents();
});
}