0

我一直在寻找一种方法来控制路径中的曲线和/或锚点,例如使用 curveTo 绘制。

基本上,当我画这样的东西时:

thingy.graphics.curveTo(220,100,150,140);
thingy.graphics.curveTo(60,200,50,300);
thingy.graphics.curveTo(40,495,250,500);
thingy.graphics.curveTo(460,495,450,300);

当我在函数中执行某些操作(例如拖动锚点)时,我想动态更改这些曲线。换句话说,我只是想更新某个曲线的坐标,比如:

覆盖

thingy.graphics.curveTo(220,100,150,140);

thingy.graphics.curveTo(120,100,250,670);

或者

thingy.graphics.curveTo(220,100,mouseX,mouseY);

例如。

在谷歌搜索我的问题的答案时,我只能找到具有非常复杂公式的长文章,大多数时候甚至没有任何 AS3 代码。由于我对数学不是很好,我更喜欢一个简单的答案,它只是显示一种方法来做到这一点。

或者,我不介意控制在 Flash IDE 中绘制的曲线,如果这样更容易的话。

4

1 回答 1

0

这是我将如何处理它。

private var curveVals:Array = [];

private var thingy:Sprite;

public function constructor() {
   thingy = new Sprite();

   var obj:Object = {cx:220,cy:100,ax:150,ay:140}
   curveVals.push(obj);
   thingy.graphics.curveTo(220,100,150,140);

   obj = {cx:60,cy:200,ax:50,ay:300}
   curVals.push(obj);
   thingy.graphics.curveTo(60,200,50,300);
}

private function storeVals(cx,cy,ax,ay,index):void {
    var obj:Object = {cx:cx,cy:cy,ax:ax,ay:ay};
    curveVal[index] = obj;
    redraw();
}

private function redraw():void {
    thingy.graphics.clear();
    // loop through values and redraw
}
于 2013-01-15T17:13:12.693 回答