首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在tween.js中创建无限动画

在tween.js中创建无限动画
EN

Stack Overflow用户
提问于 2015-12-14 22:35:19
回答 1查看 1.2K关注 0票数 0

我正在为一个沿着一条线的所有顶点移动的球创建一个动画。我有这样的代码:

代码语言:javascript
复制
var vertices = mesh.geometry.vertices;
var duration = 100;
// 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();

}

当球体位于最后一个顶点时,我可以做些什么,使这个字段重新开始动画。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-15 18:46:28

我和yavg私下聊了聊,下面的解决方案起作用了:

代码语言:javascript
复制
var vertices = mesh.geometry.vertices;
var duration = 10;

function startToEnd() {
  var i = 0;
  async.eachSeries(vertices, function(vertice, callback) {
    if (i !== 0) {
      sphere.position.copy(vertices[i - 1]);
      new TWEEN.Tween(sphere.position).to(vertices[i], duration).delay(duration).onComplete(function() {
        callback(null);
      }).start();
    } else {
      callback(null);
    }
    i++;
  }, startToEnd);
}
startToEnd();

它会从vertix开始一直到最后,然后无穷无尽地重复这个过程。不过,它确实使用了异步库,以便为我实现从一个vertix到另一个vertix的the。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34277887

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档