我不确定我的帧率代码是否正确,并且我无法找到我正在寻找的确切示例。
本质上我有子类java.awt.Component
化,并且在paint(Graphics)
方法内部我调用了我的calculateFrameRate()
函数,如下所示。我不做任何增量绘图update()
。这个数字似乎很高,我想知道 Component 类的固有双缓冲是否意味着调用paint的次数是渲染的两倍?我对双缓冲的东西生疏了,这可能是完全不正确的。
下面是帧率方法:
private List<Long> updateTimes = new ArrayList<Long>();
private void calculateFrameRate() {
long time = System.currentTimeMillis();
updateTimes.add(new Long(time));
// We will have the wrong framerate for the first 30 draws. No big.
float timeInSec = (time - updateTimes.get(0)) / 1000f;
currentFrameRate_ = 30f / timeInSec;
if (updateTimes.size() == 31)
updateTimes.remove(0);
}
干杯,
哈米