我從我學習的書中抓住了這一點。這是一個合適的Android遊戲循環嗎?
public void run()
{
// this is the method that gets called when the thread is started.
// first we get the current time before the loop starts
long startTime = System.currentTimeMillis();
// start the animation loop
while (running)
{
// we have to make sure that the surface has been created
// if not we wait until it gets created
if (!holder.getSurface().isValid())
continue;
// get the time elapsed since the loop was started
// this is important to achieve frame rate-independent movement,
// otherwise on faster processors the animation will go too fast
float timeElapsed = (System.currentTimeMillis() - startTime);
// is it time to display the next frame?
if (timeElapsed > FRAME_RATE)
{
// compute the next step in the animation
update();
// display the new frame
display();
// reset the start time
startTime = System.currentTimeMillis();
}
}
// run is over: thread dies
}
它是否正確地解釋滯後並且是否最優?
我的意思是,如果視頻不能每秒更新60次,update()會被稱爲每秒60次?
感謝
你能更具體嗎? –
看到我的編輯.... – jmasterx