我一直在閱讀遊戲循環,並且很難理解插值的概念。從我目前看到的情況來看,高級遊戲循環設計應該看起來像下面的示例。瞭解插值
假設我們希望我們的LOOP採取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...
}
}
讓我們假設更新()和render()都只拿1個滴答,而讓我們49只蜱睡覺。雖然這對我們的目標節拍率非常有用,但由於睡眠時間太長,它仍然會導致「顫抖」的動畫。爲了適應這種情況,我會假設某種渲染應該在第一種情況下進行。我只是發現大多數代碼示例傳遞一個插值到這樣的渲染方法...
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刻度的睡眠時間?如果有人知道一篇文章或樣本,我可以檢查出來,請讓我知道,因爲我不知道什麼是插值的最佳方法是...