Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 使圆圈出现在';s在AS3中从A点移动到B点_Actionscript 3_Flash_Shape - Fatal编程技术网

Actionscript 3 使圆圈出现在';s在AS3中从A点移动到B点

Actionscript 3 使圆圈出现在';s在AS3中从A点移动到B点,actionscript-3,flash,shape,Actionscript 3,Flash,Shape,我在AS3中有一个代码,它使船从a点移动到B点,等等 tween = new Tween(boat, "x", None.easeNone, boat.x, lastClick.x, 1, true);  tweenY = new Tween(boat, "y", None.easeNone, boat.y, lastClick.y, 1, true);  我想添加一些出现在船后面的圆圈(如地图上的路径) 我试过使用线条,但它不太适合(因为它会立即出现,当然,它不是圆形) 您知道如何添加从l

我在AS3中有一个代码,它使船从a点移动到B点,等等

tween = new Tween(boat, "x", None.easeNone, boat.x, lastClick.x, 1, true); 
tweenY = new Tween(boat, "y", None.easeNone, boat.y, lastClick.y, 1, true); 

我想添加一些出现在船后面的圆圈(如地图上的路径)

我试过使用线条,但它不太适合(因为它会立即出现,当然,它不是圆形)


您知道如何添加从
lastClick
event.currentTarget
的圆圈吗

因为您使用的是tween,所以您可以在tween更新时绘制点。如果直接在时间轴上编写代码,则可能需要从函数中删除“private”:

// draw a point every X pixels
private var DISTANCE_BETWEEN_POINTS:int = 20;
private var pointsArray:Array = [];
private var lastPoint:Point;

tween = new Tween(boat, "x", null, boat.x, lastClick.x, 1, true);
tween.addEventListener(TweenEvent.MOTION_CHANGE, onTweenUpdate);
tween.addEventListener(TweenEvent.MOTION_FINISH, onTweenEnd);

tweenY = new Tween(boat, "y", null, boat.y, lastClick.y, 1, true);
tweenY.addEventListener(TweenEvent.MOTION_CHANGE, onTweenUpdate);
tweenY.addEventListener(TweenEvent.MOTION_FINISH, onTweenEnd);

// for the start we assume the last drawn point was at the boat origin
lastPoint = new Point(boat.x, boat.y);    

// called on every tween update
private function onTweenUpdate(e:TweenEvent):void
{
    // draw a point if the distance to the last point is greater than DISTANCE_BETWEEN_POINTS
    if (distance(lastPoint.x, lastPoint.x, boat.y, lastPoint.y) > DISTANCE_BETWEEN_POINTS)
    {
        // pseudocode here. Add your points as movieclips or just draw circles
        // you might adjust the point position as this will draw a point over the boat.
        // you might want to add a layer where you draw points that will be under your boat
        var point:MovieClip = new PointMC();
        point.x = boat.x;
        point.y = boat.y;
        addChild(point);

        // remember the last drawn point position for the next one
        lastPoint = new Point(boat.x, boat.y);

        // add point to array so we can remove them when the tween is done
        pointsArray.push(point);
    }
}

// called when a tween ends
// remove event listeners so your tweens can be garbage collected
private function onTweenEnd(e:TweenEvent):void
{
    tween.removeEventListener(TweenEvent.MOTION_CHANGE, onTweenUpdate);
    tween.removeEventListener(TweenEvent.MOTION_FINISH, onTweenEnd);
    tweenY.removeEventListener(TweenEvent.MOTION_CHANGE, onTweenUpdate);
    tweenY.removeEventListener(TweenEvent.MOTION_FINISH, onTweenEnd);

    removePoints();
}

private function removePoints():void
{
    for (var i:int = 0; i < pointsArray.length; i++)
    {
        removeChild(pointsArray[i]);
    }

    pointsArray = [];
}

// measures the distance between two points
private function distance(x1:Number, x2:Number, y1:Number, y2:Number):Number
{
    var dx:Number = x1 - x2;
    var dy:Number = y1 - y2;
    return Math.abs(Math.sqrt(dx * dx + dy * dy));
}

此外,它还可以做很多其他的事情,比如贝塞尔曲线、反转等等。一旦你习惯了,你会问自己没有它之前你是如何生活的:)

在提出问题之前,请阅读官方文档或用谷歌搜索它,因为“as3画圈”输出了一个完全相关的链接:然后,您需要订阅事件。请输入_FRAME Event并在此时船所在的位置画圆圈。谢谢!但是我有这个错误。。错误1119无法通过静态类访问属性TWEEN_UPDATE。知道为什么吗?它确实起作用了!谢谢。不知道TweenEvent.MOTION\u FINISH的目的是什么,但如果我取消激活tweenY.addEventListener(TweenEvent.MOTION\u FINISH,onTweenEnd)行,则
tweenY.addEventListener(TweenEvent.MOTION\u FINISH,onTweenEnd)正在工作..目的是在运动完成后再次删除事件侦听器,以便垃圾收集器可以释放内存。它应该去掉这些点。我刚刚注意到我忘了在ontweenen函数中将“addEventListener”改为“removeEventListener”错过了你的其他评论,应该是TweenEvent.MOTION\u FINISH而不是TWEEN\u UPDATE当然,编辑了我的回复
// draw a point every X pixels
private var DISTANCE_BETWEEN_POINTS:int = 20;
private var pointsArray:Array = [];
private var lastPoint:Point;

tween = new Tween(boat, "x", null, boat.x, lastClick.x, 1, true);
tween.addEventListener(TweenEvent.MOTION_CHANGE, onTweenUpdate);
tween.addEventListener(TweenEvent.MOTION_FINISH, onTweenEnd);

tweenY = new Tween(boat, "y", null, boat.y, lastClick.y, 1, true);
tweenY.addEventListener(TweenEvent.MOTION_CHANGE, onTweenUpdate);
tweenY.addEventListener(TweenEvent.MOTION_FINISH, onTweenEnd);

// for the start we assume the last drawn point was at the boat origin
lastPoint = new Point(boat.x, boat.y);    

// called on every tween update
private function onTweenUpdate(e:TweenEvent):void
{
    // draw a point if the distance to the last point is greater than DISTANCE_BETWEEN_POINTS
    if (distance(lastPoint.x, lastPoint.x, boat.y, lastPoint.y) > DISTANCE_BETWEEN_POINTS)
    {
        // pseudocode here. Add your points as movieclips or just draw circles
        // you might adjust the point position as this will draw a point over the boat.
        // you might want to add a layer where you draw points that will be under your boat
        var point:MovieClip = new PointMC();
        point.x = boat.x;
        point.y = boat.y;
        addChild(point);

        // remember the last drawn point position for the next one
        lastPoint = new Point(boat.x, boat.y);

        // add point to array so we can remove them when the tween is done
        pointsArray.push(point);
    }
}

// called when a tween ends
// remove event listeners so your tweens can be garbage collected
private function onTweenEnd(e:TweenEvent):void
{
    tween.removeEventListener(TweenEvent.MOTION_CHANGE, onTweenUpdate);
    tween.removeEventListener(TweenEvent.MOTION_FINISH, onTweenEnd);
    tweenY.removeEventListener(TweenEvent.MOTION_CHANGE, onTweenUpdate);
    tweenY.removeEventListener(TweenEvent.MOTION_FINISH, onTweenEnd);

    removePoints();
}

private function removePoints():void
{
    for (var i:int = 0; i < pointsArray.length; i++)
    {
        removeChild(pointsArray[i]);
    }

    pointsArray = [];
}

// measures the distance between two points
private function distance(x1:Number, x2:Number, y1:Number, y2:Number):Number
{
    var dx:Number = x1 - x2;
    var dy:Number = y1 - y2;
    return Math.abs(Math.sqrt(dx * dx + dy * dy));
}
// move the boat to x and y in one go - DONE :)
TweenLite.to(boat, 1, {x: lastClick.x, y: lastClick.y, onUpdate: onTweenUpdate});