kineticjs:我可以将拖拽界限设置为圆形轨迹吗?

时间:2012-08-27 03:05:32

标签: kineticjs

我看到拖拽的样本就像:

// set drag bounds after instantiation
shape.setDragBounds({
  top: 0,
  left: 0,
  right: 200,
  bottom: 200
});

但可以将其设置为圆形轨道吗?谢谢你的关注。

1 个答案:

答案 0 :(得分:2)

是的,可以这样做:

dragBoundFunc: function(pos) {
        var x = 100;  // your center point
        var y = 100;  // your center point 
        var radius = 50;
        var scale = radius / Math.sqrt(Math.pow(pos.x - x, 2) + Math.pow(pos.y - y, 2)); // distance formula ratio
        if(scale < 1)
          return {
            y: Math.round((pos.y - y) * scale + y),
            x: Math.round((pos.x - x) * scale + x)
          };
        else
          return pos;
      }