Original Post
I made an fps counter for a 2d game I'm making. I ran the counter on my desktop, which has a 9800 gx2 and a dual core 2.4 ghz processor. My fps was in the hundreds when I saw drawing lines and text and a small amount of images on the screen. However, when I got to the part where I draw lots of 40x40 tiles on the screen, the fps drops to 11. The same exact code running on my laptop, with an Intel 945GM and a 2.0 ghz processor, shows very close to 60 fps throughout. My problem is that I don't know how the fps for my desktop could be that much lower when it is clearly superior in terms of hardware. The code for fps counter and the main loop is below. The method I use for drawing the map tiles (they are pngs) is Graphics2D.drawImage(bufferedImage, x, y, null); and I draw right to the Graphics object that I pass to the render method. If anyone wants to see more code, I'll be glad to post it. I don't even know where to start fixing this problem. Is the fps counter somehow wrong? Should I try something more high res than System.currentTimeMillis()? Is there some more efficient way to draw images?
public LostHavenRPG(GraphicsDevice device) {
try {
GraphicsConfiguration gc = device.getDefaultConfiguration();
frmMain = new Frame(gc);
frmMain.setUndecorated(true);
frmMain.setIgnoreRepaint(true);
device.setFullScreenWindow(frmMain);
if (device.isDisplayChangeSupported())
chooseBestDisplayMode(device);
frmMain.addMouseListener(this);
frmMain.addKeyListener(this);
frmMain.createBufferStrategy(2);
BufferStrategy bufferStrategy = frmMain.getBufferStrategy();
g = bufferStrategy.getDrawGraphics();
gameState = GameState.Main;
auxState = AuxState.None;
done = false;
showFps = false;
frameCount = 0;
lastFrameCount = 0;
lastFpsUpdate = System.currentTimeMillis();
playerX = 400;
playerY = 300;
loadGUI(bufferStrategy);
loadMap();
while (!done) {
g = bufferStrategy.getDrawGraphics();
handleGameEvents();
render(g);
g.dispose();
bufferStrategy.show();
frameCount++;
if(System.currentTimeMillis()-1000 >= lastFpsUpdate) {
lastFpsUpdate = System.currentTimeMillis();
lastFrameCount = frameCount;
frameCount = 0;
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
device.setFullScreenWindow(null);
}
}