1

我有一个非常具体的问题,其中我有一个对象沿着一个向量移动,该向量最终会到达目标点并停止移动。所讨论的对象是具有“飞行”动画序列、“着陆”动画序列和“空闲”动画序列的资产。

对象必须以固定速度沿着从舞台上随机点出发的直线移动。当物体距离终点正好 30 帧时,物体将开始缓动,在该终点它将变为着陆序列(这需要 30 帧,或基于 frameRate 的一秒)。一旦着陆序列完成,缓动应该向下舍入到 0,其中对象已经完成了它的旅程,现在无限期地切换到“空闲”序列。

我在下面提供了一个屏幕截图来展示我的问题。任何帮助将不胜感激,因为数学和何时播放着陆序列给了我最多的问题。我试图让飞行 -> 着陆 -> 空转的过程非常顺畅和自然。

我正在使用 ActionScript3 并且 SWF 以或接近 30fps 的速度运行!

截图说明:http: //i.stack.imgur.com/oWrEg.png

4

1 回答 1

1

我建议您使用 Tweenlite 库。

这是一些伪代码:

// determine x,y landing location
// calculate the angle between ship's x,y & landing location.
// calculate the x,y location along that angle that the landing animation should begin
// Tween from ship's x,y to the x,y where landing sequence should begin
    // set the onComplete parameter to call the function that triggers the landing sequence
// Tween from ship's current location to the landing location
    // set onComplete parameter to call function that sets ship to idle animation

如果您使用 Tweenlite,这是一个如何设置 tween 的示例:

Tweenlite.to(ship, duration, {x:targetX, y:targetY, onComplete:startLandingSequence});

-- 持续时间是飞船从当前位置到达着陆序列应该开始的位置需要多长时间。

当使用补间进行此类操作时,您需要根据其速度计算您的船到达给定位置需要多长时间。该值是您将作为补间持续时间传递的值。

duration = distance / speedInPixelsPerSecond;

就您在评论中提出的计算向量而言,这里有一个很棒的向量教程:

http://www.tonypa.pri.ee/vectors/as3/start.html

于 2013-04-10T21:31:14.490 回答