【问题标题】:events not working on custom shapes in kineticjs事件不适用于 kineticjs 中的自定义形状
【发布时间】:2012-12-28 15:08:18
【问题描述】:

我已经使用 Kinetic.Shape 在 kineticjs 中绘制了自定义形状,然后我正在尝试将鼠标事件附加到该形状。但是该事件永远不会触发:

var myShape = new Kinetic.Shape({
      drawFunc: function (canvas) {
              var context = canvas.getContext();
              context .beginPath();
              context .moveTo(47.1, 139.8);
              context .lineTo(50.5, 137.6);
              .
              .
              .
              context .closePath();
              context .fillStyle = color;
              context .fill();

          },
          fill: '#2369e7',
          stroke: 'black',
          strokeWidth: 2
      });

myShape.on('mousedown', function ()
      {
          //this never fires
      });

我尝试了使用 Circle 和 Rectangle 的事件,例如示例文档,它可以工作。但是对于 Kinetic.Shape 对象,事件永远不会触发。有什么想法吗?

【问题讨论】:

  • 也许您还需要实现类似containsFunc 的东西?

标签: kineticjs


【解决方案1】:

通过在 drawFunc 的末尾添加这个来修复它:

canvas.fillStroke(this);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多