【问题标题】:Flash / Actionscript line thickness will draw lines outside co-ordinates given in lineToFlash / Actionscript 线条粗细将在 lineTo 中给定的坐标之外绘制线条
【发布时间】:2014-03-20 02:46:01
【问题描述】:

这是我在使用 AS 绘图时遇到的一个非常基本的问题。假设我有以下代码。

g.lineStyle(20, 0xff0000, 1, false);
g.moveTo(10, 10);
g.lineTo(210, 10);   

因为线条粗细为 20。这实际上将绘制一条从 (0,0) 到 (220, 20) 的矩形线。即厚度/2 将被添加到每个维度中。

我想知道: 1.这是对的还是我弄错了? 2. 所以每次我们需要在不希望它被约束的地方画线时,例如绘制内部边界我们需要考虑到这一点,这样线就不会超出特定区域。这也是正确的吗?

【问题讨论】:

    标签: flash actionscript drawing line


    【解决方案1】:

    是的,1) 是正确的。关于 2) 实际上 getRect() 方法不会考虑笔画宽度。这是一个代码:

    stop();
    
    var mc:MovieClip = new MovieClip();
    
    var gr:Graphics = mc.graphics;
    
    
    //Draw a rectangle 50x50
    gr.lineStyle(20);
    gr.beginFill(0, 0.5);
    gr.drawRect(0, 0, 50, 50);
    gr.endFill();
    
    this.addChild(mc);
    
    //Will trace (x=0, y=0, w=50, h=50)
    trace(mc.getRect(this));
    
    //Will trace (x=-10, y=-10, w=70, h=70)
    trace(mc.getBounds(this));
    

    【讨论】:

      猜你喜欢
      • 2015-12-12
      • 2011-01-17
      • 1970-01-01
      • 2013-05-03
      • 2021-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多