【问题标题】:Issues when drawing using scale使用比例绘制时的问题
【发布时间】:2018-10-02 19:59:22
【问题描述】:

我有一个 KonvaJS 应用程序,我正在使用 scale 选项处理一个问题。

您可以在这里看到问题: Issue example

我使用 KonvaJS Line 类进行绘制,它工作正常。但是当我改变舞台比例时,问题就出现了。就像光标在不同的位置一样。

我尝试了不同的解决方案,但没有运气。

关于如何解决这个问题的任何想法?

提前致谢。

【问题讨论】:

    标签: konvajs


    【解决方案1】:

    您只需要调整鼠标位置以适应舞台变换。你可以这样做:

      const pos = stage.getPointerPosition();
    
      const stageTransform = stage.getAbsoluteTransform().copy();
      const position = stageTransform.invert().point(pos);
    
      layer.add(new Konva.Circle({
        x: position.x,
        y: position.y,
        radius: 10,
        fill: 'red'
      }));
    

    演示:http://jsbin.com/gaqepodivu/1/edit?js,output

    【讨论】:

      猜你喜欢
      • 2020-11-29
      • 2020-08-10
      • 1970-01-01
      • 1970-01-01
      • 2010-11-21
      • 1970-01-01
      • 1970-01-01
      • 2016-02-24
      • 1970-01-01
      相关资源
      最近更新 更多