【问题标题】:Understanding Interpolation了解插值
【发布时间】:2014-04-11 18:35:10
【问题描述】:

我一直在阅读有关游戏循环的内容,但很难理解插值的概念。从我目前看到的情况来看,高级游戏循环设计应该类似于下面的示例。

假设我们希望我们的循环获得 50 TICKS

while(true){
  beginTime = System.currentTimeMillis();
  update();
  render();
  cycleTime = System.currentTimeMillis() - beginTime;

  //if processing is quicker than we need, let the thread take a nap
  if(cycleTime < 50)
    Thread.sleep(cycleTime);
  )

  //if processing time is taking too long, update until we are caught up
  if(cycleTime > 50){
  update();
  //handle max update loops here...
  }
}

让我们假设 update() 和 render() 都只需要 1 个滴答声即可完成,剩下 49 个滴答声进入睡眠状态。虽然这对我们的目标滴答率很有帮助,但由于睡眠时间过长,它仍然会导致“抽搐”动画。为了对此进行调整,而不是睡觉,我会假设某种渲染应该在第一个 if 条件内进行。我发现的大多数代码示例只是像这样将一个插值传递给渲染方法......

while(true){
  beginTime = System.currentTimeMillis();
  update();
  render(interpolationValue);
  cycleTime = System.currentTimeMillis() - beginTime;

  //if processing is quicker than we need, let the thread take a nap
  if(cycleTime < 50)
    Thread.sleep(cycleTime);
  )

  //if processing time is taking too long, update until we are caught up
  if(cycleTime > 50){
  update();
  //handle max update loops here...
  }

  interpolationValue = calculateSomeRenderValue();
}

由于 49 滴答的睡眠时间,我只是不明白这是如何工作的?如果有人知道我可以查看的文章或示例,请告诉我,因为我不确定插值的最佳方法是什么......

【问题讨论】:

    标签: android interpolation game-loop


    【解决方案1】:

    我知道有点晚了,但希望这篇文章会有所帮助 http://gameprogrammingpatterns.com/game-loop.html

    它很好地解释了游戏时间安排。我认为您有点困惑的主要原因是因为将渲染函数传递给当前经过的时间。哦,当然这取决于您使用的系统,但通常渲染不会以任何方式修改场景,它只会绘制它,因此它不需要知道已经过去了多少时间。

    然而,更新调用会修改场景中的对象,并且为了使它们保持及时(例如播放动画、Lerps 等),那么更新函数需要知道全局或自最后一次更新。

    无论如何,我没有必要公平地讨论它......那篇文章非常有用。

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-17
      • 2017-03-10
      • 1970-01-01
      • 2013-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-28
      相关资源
      最近更新 更多