问题:我有一个程序涉及从一侧到另一侧移动一个栏(如砖块)。问题是它在Eclipse内部运行时的速度与导出到桌面时的速度不同。
研究:
阅读本文时,我认为我可能无法正确创建delta值,这可以解释为什么它以不同的速度运行。 my computer is carrying out java programs which i have created to fast [closed]
阅读这篇文章后,我发现可能 Eclipse编译器只是更快,这可能导致速度差异。 Application runs faster in eclipse
// run() is being ran with a while(true) game loop
public void run(Input input)
{
init();
// Ran at 60 FPS
if(fps.tick())
render();
// Ran as fast as possible
update(input);
}
private void render()
{
start = System.nanoTime();
if(render.getGraphics() != null)
{
Graphics g = render.getBS().getDrawGraphics();
g.drawImage(new BufferedImage(Reference.WIDTH*Reference.SCALE, Reference.HEIGHT*Reference.SCALE,
BufferedImage.TYPE_INT_RGB), 0,0, AppGameContainer.canvas);
activeState.render(render.getGraphics(), AppGameContainer.canvas);
render.getGraphics().dispose();
render.getBS().show();
}
end = System.nanoTime();
// Time in ms
delta = (end-start)/1000000.0;
}
我有一个视频如果感兴趣,可以直观地表示问题:Video of issue
答案 0 :(得分:-1)
// run() is being ran with a while(true) game loop
public void run(Input input)
{
start = System.nanoTime();
init();
// Ran at 60 FPS
if(fps.tick())
render();
// Ran as fast as possible
update(input);
end = System.nanoTime();
// Time in ms
delta = (end-start)/1000000.0;
}
private void render()
{
if(render.getGraphics() != null)
{
Graphics g = render.getBS().getDrawGraphics();
g.drawImage(new BufferedImage(Reference.WIDTH*Reference.SCALE, Reference.HEIGHT*Reference.SCALE,
BufferedImage.TYPE_INT_RGB), 0,0, AppGameContainer.canvas);
activeState.render(render.getGraphics(), AppGameContainer.canvas);
render.getGraphics().dispose();
render.getBS().show();
}
}