0


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

我使用简单的绘图演示开始,所以我有一个绘图功能的 mousedown 事件

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);
});
4

1 回答 1

0
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);
});
于 2020-06-19T12:28:56.153 回答