代码之家  ›  专栏  ›  技术社区  ›  slashnick Epirocks

是否可以使用Flex旋转动态添加的线?

  •  2
  • slashnick Epirocks  · 技术社区  · 17 年前

    我正在使用 canvas.moveTo(0, 0); canvas.lineTo(100, 100); ,但我希望用户移动鼠标以设置线的旋转。谷歌建议使用 rotation

    3 回复  |  直到 17 年前
        1
  •  2
  •   Christian Nunciato    17 年前

    通常,您可以操纵图形绘制到的曲面——通常是一个Sprite实例,因为它非常轻量级,非常适合该任务。相反,如果您创建了一个新的精灵,使用其图形对象绘制线条、形状等,将精灵添加到UIComponent中——如果不先将精灵包装到UIComponent实例中,就无法将其直接添加到画布中——然后将该UIComponent添加到画布中,您可以通过旋转、移动等直接操纵精灵。

    override protected function createChildren():void
    {
        super.createChildren();
    
        // Create a new Sprite and draw onto it
        var s:Sprite = new Sprite();
        s.graphics.beginFill(0, 1);
        s.graphics.drawRect(0, 0, 20, 20);
        s.graphics.endFill();
    
        // Wrap the Sprite in a UIComponent
        var c:UIComponent = new UIComponent();
        c.addChild(s);
    
        // Rotate the Sprite (or UIComponent, whichever your preference)
        s.rotation = 45;
    
        // Add the containing component to the display list
        this.addChild(c);
    }
    

    希望有帮助!

        2
  •  1
  •   CookieOfFortune    17 年前

    可以

    请看ASDocs中的示例: Rotating things

        3
  •  1
  •   kenneth    17 年前

    什么是画布(实际的画布没有lineTo()或moveTo()方法)?

    看起来您可能正在操纵画布的图形对象。在这种情况下,您最好执行以下操作

    private var sp : Sprite;
    //canvas is whatever Canvas you wish to add the sprite to
    private function addLine(canvas : Canvas) : void {
    sp = new Sprite();
    /* Do the drawing of the sprite here,
       such as sp.graphics.moveTo or sp.graphics.lineTo */
    sp.rotation = 45;
    canvas.rawChildren.addChild(sp);
    }
    

    然后,每当您希望更改旋转时,只需更新sp.rotation(现在位于画布中)

    推荐文章