代码之家  ›  专栏  ›  技术社区  ›  Adam Alexander

在createjs textAlign Center导致命中区域未对齐

  •  0
  • Adam Alexander  · 技术社区  · 11 年前

    当我将文本设置为链接,设置边界形状,并将命中区域设置为边界形状时,如果textAlign='center',我的命中区域将关闭。有什么想法吗?

    var linkColor = "#0000ff";
    var linkFont = "bold 14px Times";
    
    var presentationLink = new createjs.Text("View Presentation", linkFont, linkColor);
    presentationLink.textAlign = "left";
    presentationLink.maxWidth = 170;
    presentationLink.x = 300;
    presentationLink.y = 125;
    stage.addChild(presentationLink);
    

    var plBounds=presentationLink.getTransformedBounds();

    var s = new createjs.Shape().set({ x: plBounds.x, y: plBounds.y + plBounds.height });
    s.graphics.s(linkColor).moveTo(0, 0).lineTo(plBounds.width, 0);
    stage.addChild(s);
    
    var hitAreaForPLink = new createjs.Shape(new createjs.Graphics().beginFill("#ffffff").drawRect(-10, -10, plBounds.width + 20, plBounds.height + 10));
    presentationLink.hitArea = hitAreaForPLink;
    
    stage.enableMouseOver();
    
    presentationLink.on("mouseover", function () {
        presentationLink.cursor = "pointer";
    });
    
    1 回复  |  直到 11 年前
        1
  •  1
  •   gskinner    11 年前

    这个 hitArea 根据其所有者的坐标系定位。也就是说,所有所有者的转换都应用于 hit区域 。这样,如果要为所有者设置动画 hit区域 将按照预期进行跟踪。

    由于转换已应用,因此需要使用 getBounds 不 getTransformedBounds 。请参见此示例: http://jsfiddle.net/gskinner/uagv5t84/2/