Konvajs在移动绘图线时绘制第一个点




我有以下问题:我正在使用konvajs来构建一个画布,您可以在其中绘制例如线条。另外,您应该能够移动这些线条。直到这里没有问题,给行可拖动的属性一切正常。但是当我移动线条时,我仍然在开始时画一个点。当我移动直线时,如何防止第一个点绘制?

我使用了简单的绘图演示作为开始,所以我有一个用于绘图功能的鼠标按下事件

stage.on('mousedown touchstart', function (e) {
isPaint = true;
var pos = stage.getPointerPosition();
lastLine = new Konva.Line({
stroke: strokeColor,
strokeWidth: 5,
draggable: true,
lineCap: 'round',
globalCompositeOperation:
mode === 'brush' ? 'source-over' : 'destination-out',
points: [pos.x, pos.y],
});
layer.add(lastLine);
});
stage.on('mousedown touchstart', function (e) {
// start drawing only when we are on empty area
const onEmptySpace = e.target.getLayer() === backgroundLayer;
if (!onEmptySpace) {
return;
}
isPaint = true;
var pos = stage.getPointerPosition();
lastLine = new Konva.Line({
stroke: strokeColor,
strokeWidth: 5,
draggable: true,
lineCap: 'round',
globalCompositeOperation:
mode === 'brush' ? 'source-over' : 'destination-out',
points: [pos.x, pos.y],
});
layer.add(lastLine);
});

最新更新