Possible to get faster FPS with this code?
This is a stripped down version of the code I've been using to run my game. It's basically a 1024x768 frame being run in fullscreen mode and scaled to fit any resolution with some 2d graphics put on top of it. On my machine I get 60 fps just like this, but it drops a lot as soon as I add any images. What kind of fps should I be shooting for and in what ways can I improve this, or should I be using another approach altogether?
import javax.swing.JFrame;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.GraphicsDevice;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferStrategy;
import java.awt.geom.AffineTransform;
publicclass testimplements Runnable{
JFrame mainFrame;
BufferStrategy bufferStrategy;
GraphicsConfiguration gc;
int mouseX, mouseY;
Thread animThread;
Graphics2D g;
AffineTransform a;
double timer;
double frames;
double currentFPS;
double scaleX;
double scaleY;
int gcx, gcy;
public test(GraphicsDevice device){
timer = System.currentTimeMillis();
frames = 0.0;
currentFPS = 0.0;
try{
gc = device.getDefaultConfiguration();
mainFrame =new JFrame(gc);
mainFrame.setUndecorated(true);
mainFrame.setIgnoreRepaint(true);
scaleX = gc.getBounds().getWidth()/1024.0;
scaleY = gc.getBounds().getHeight()/768.0;
a =new AffineTransform();
a.scale(scaleX, scaleY);
gcx = (int) gc.getBounds().getWidth();
gcy = (int) gc.getBounds().getHeight();
mainFrame.setVisible(true);//Keep this in front of .createBufferStrategy()
mainFrame.createBufferStrategy(2);
bufferStrategy = mainFrame.getBufferStrategy();
this.start();
device.setFullScreenWindow(mainFrame);
while(true){
}
}catch (Exception e){e.printStackTrace();}
}
privatevoid render(Graphics2D g){
g.fillRect(0, 0, 1023, 768);
g.setColor(Color.red);
g.drawString(currentFPS+"", 10, 35);
}
publicvoid start(){
if(animThread ==null){
animThread =new Thread(this);
animThread.start();
}
}
publicvoid run(){
while(Thread.currentThread() == animThread){
g = (Graphics2D) bufferStrategy.getDrawGraphics();
if(!(scaleX == 1.0 & scaleY == 1.0)) g.transform(a);
render(g);
g.dispose();
bufferStrategy.show();
frames+=1;
if(frames == 7){
currentFPS = (frames / (System.currentTimeMillis()-timer))*1000.0;
frames = 0;
timer = System.currentTimeMillis();
}
//try {
//animThread.sleep(17);
//} catch (InterruptedException e) {}
}
}
publicstaticvoid main(String[] args){
try{
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();
test gameGraphics =new test(device);
}catch (Exception e){e.printStackTrace();}
System.exit(0);
}
}
Once again, I get about 60 fps with no images and it goes to 15-25 when I put them on. What should I be expecting and can I improve it?

