Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.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
Javascript 在tween.js中沿另一个对象移动对象创建动画_Javascript_Animation_Tween.js - Fatal编程技术网

Javascript 在tween.js中沿另一个对象移动对象创建动画

Javascript 在tween.js中沿另一个对象移动对象创建动画,javascript,animation,tween.js,Javascript,Animation,Tween.js,我有一个物体是线。我想用一个物体制作一个动画,它可以移动直线的所有顶点,它可以是一个球体。为此,我将使用tween.js。我的问题是,我无法实现其所有顶点的动画。如何使动画从起点一直显示到终点?。我有以下代码: 我使用“.to”方法,如果我将要移动的顶点放在其中,效果很好。但是如果我有1000个顶点,我就必须把它们全部放进去。我能做什么。我需要沿直线移动球体。您只需创建一个循环,指定每个顶点的过渡。您还需要将球体的位置设置为上一个顶点,否则将缓存该位置,并且每个二者将在执行循环之前从球体的位置

我有一个物体是线。我想用一个物体制作一个动画,它可以移动直线的所有顶点,它可以是一个球体。为此,我将使用tween.js。我的问题是,我无法实现其所有顶点的动画。如何使动画从起点一直显示到终点?。我有以下代码:


我使用“.to”方法,如果我将要移动的顶点放在其中,效果很好。但是如果我有1000个顶点,我就必须把它们全部放进去。我能做什么。我需要沿直线移动球体。

您只需创建一个循环,指定每个顶点的过渡。您还需要将球体的位置设置为上一个顶点,否则将缓存该位置,并且每个二者将在执行循环之前从球体的位置开始。此外,由于这些tween在循环中执行得非常快,因此需要指定一个延迟,以便转换可以在正确的时间开始

// Get the vertices for each line.
var vertices = line.geometry.vertices;
// Specify the duration for each tween.
var duration = 500;
// Iterate through each vertex in the line, starting at 1.
for (var i = 1, len = vertices.length; i < len; i++) {
    // Set the position of the sphere to the previous vertex.
    sphere.position.copy(vertices[i - 1]);
    // Create the tween from the current sphere position to the current vertex.
    new TWEEN.Tween(sphere.position).to(vertices[i], duration).delay(i * duration).start();
}
//获取每行的顶点。
var顶点=line.geometry.vertices;
//指定每种吐温的持续时间。
var持续时间=500;
//从1开始遍历直线中的每个顶点。
对于(var i=1,len=vertices.length;i
哦,非常有趣,非常感谢!。我有个问题。我需要做的是在直线上放置一些球体并创建一个动画?我想沿着直线移动几个区域并保持相同的距离。当第n个球体到达直线末端时会发生什么?一个新的产卵在生产线的开始吗?这似乎是一个更棘手的问题,至少您需要跟踪第n个球体何时位于最后一个顶点,并决定从那里执行什么操作(反转动画、移除动画等)。您还需要在动画开始时确定球体是否位于每个顶点上,或者如果从一个球体开始,它将在下一个顶点之间,并在第一个顶点创建另一个球体,然后重复此过程。我已经考虑过这样做。当第一个球体结束动画时,动画将无限大。从顶点0重新启动,直到最后一个顶点。我想,所有的球体都有一个动画,正如我在图中所示。我不知道该怎么做,如我所说的同步动画。n个球体做我想做的。我怎么做才能使动画无限大?。我希望在完成时从第一个顶点重新开始。
// Get the vertices for each line.
var vertices = line.geometry.vertices;
// Specify the duration for each tween.
var duration = 500;
// Iterate through each vertex in the line, starting at 1.
for (var i = 1, len = vertices.length; i < len; i++) {
    // Set the position of the sphere to the previous vertex.
    sphere.position.copy(vertices[i - 1]);
    // Create the tween from the current sphere position to the current vertex.
    new TWEEN.Tween(sphere.position).to(vertices[i], duration).delay(i * duration).start();
}