1

所以,我正在创建一个游戏,其中我有一艘带有枪的船,可以发射子弹。

我希望船的枪在我射击时弹回,所以看起来枪实际上是在射击子弹。到目前为止一切都很好,枪只是相对于身体移动,到目前为止没有任何东西陷入无限循环。

我的船是由我编写的完美运行的构造函数制成的,因此为了创建补间,而不是在构造函数中创建我无法重用的变量,我制作了补间对象的实际属性。

这是代码的样子:

this.gunTweenPosition = {y : unit / -1.52 + (gunLength * unit / -4)};
this.gunTweenTarget = {y : av.gunTweenPosition.y + unit / 6};
this.gunTween1 = new TWEEN.Tween(av.gunTweenPosition.y).to(av.gunTweenTarget.y, 1000);
this.gunTween2 = new TWEEN.Tween(av.gunTweenTarget.y).to(av.gunTweenPosition.y, 1000);
this.gunTween1.easing(TWEEN.Easing.Cubic.In);
this.gunTween2.easing(TWEEN.Easing.Cubic.Out);
this.gunTween1.onUpdate(function() {
  this.gun.position.y = av.gunTweenPosition.y;
});
this.gunTween2.onUpdate(function() {
  this.gun.position.y = av.gunTweenTarget.y;
});

'this' 是我们正在构建的对象,为了启动推拉枪的函数,我有一个我刚刚调用的函数:

car avatar = this;
var number = 0;
function loopTweenUpdating() {
  number++;
  if (number < 20) {
    avatar.gunTween1.update();
    avatar.gunTween1.onComplete(function() {
      avatar.gunTween2.update();
    });
    setTimeout(loopTweenUpdating, 20);
  }
}

我看不出这里有什么问题。

单击链接可查看完整代码。

有任何想法吗?

4

1 回答 1

0

看起来您缺少开始补间的时间。

this.gunTween1.start();
于 2018-12-08T19:38:04.303 回答