Easeljs:当鼠标在形状边界上时显示指针光标

4

我正在尝试实现与下面代码类似的功能。当用户处于矩形边缘时,光标指向一个指针,否则光标为箭头。

     shape.graphics.beginStroke("#000").beginFill("#daa").drawRect(50, 150, 250, 250);
     shape.on("mousemove", function(evt) {
          if (isOnEdges(evt)) {
              evt.target.cursor = "pointer";
          } else {
              evt.target.cursor = "arrow";
          }
     });

以上代码存在的问题是:

  1. 形状没有mousemove处理程序
  2. 如何计算鼠标是否在形状的边缘(isOnEdges函数)
2个回答

10

您只需将光标设置在形状上,并确保在舞台上启用enableMouseOver:

var shape = new Shape();
shape.graphics.beginStroke("#000").beginFill("#daa").drawRect(50, 150, 250, 250);
shape.cursor = "pointer";

stage.enableMouseOver();

EaselJS将自动判断您是否超出了形状的边界。


光标在形状的边缘时是指针。在你的情况下,它始终是指针。我正在尝试调整形状大小,并希望在形状边缘时出现调整大小的光标。 - user1972450

0

我有一个类似的问题:

container.on("pressmove", function (evt) {
    this.x = evt.stageX + this.offset.x;
    this.y = evt.stageY + this.offset.y;
    if (this.allowDrop(board)) {
        this.cursor = "pointer";
    }
    else {
        this.cursor = "no-drop";
    }
});

这段代码在运行时无法改变我的光标.. 我使用了一个ticker来更新舞台.. 所以这不是问题的原因。


这并不是推荐或最佳实践,但您可以使用私有API来强制舞台重新测试鼠标悬停:stage._testMouseOver(true); - Lanny

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接