【发布时间】: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