Can some people go through the source, and make some changes and tell me how they made Blue Fiend hog less CPU and RAM?
Without looking too closely, I had noticed a few things.
I haven’t noticed a BufferStrategy.
When creating loading/creating images use “createCompatibleImage”, like so:
private static BufferedImage loadImage(final String imageName){
final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice myDevice = env.getDefaultScreenDevice();
final GraphicsConfiguration graphicConf = myDevice.getDefaultConfiguration();
final ClassLoader classLoad = ImageProcess.class.getClassLoader();
Graphics2D g2d = null;
BufferedImage img;
try {
img = ImageIO.read(classLoad.getResource("Images/"+imageName));
} catch (final IOException e) {
//System.err.println(imageName + " image failed to load.");
return null;
}
final BufferedImage copy = graphicConf.createCompatibleImage(img.getWidth(), img.getHeight(),java.awt.Transparency.OPAQUE);
g2d = copy.createGraphics();
g2d.drawImage(img,null,0,0);
img.flush();
img = null;
g2d.dispose();
g2d = null;
return copy;
}
And don’t use alpha when possible. So only create alpha “createCompatibleImage” when you need it to have alpha.
That might help a little.
Have you profiled it? VisualVM is a decent profiler, and once you know where the biggest issues are you’ll be able to ask more specific questions which people may be more inclined to answer. At present you’re asking such an open-ended question that it sounds to me as though it would take a few hours to get useful results, and as you yourself have recently observed in another thread the only person who cares that much about your game is you.
Ah, this seems like it’ll be a nice tool onc3e I get it to work better. I got this info from it.
When I was moving in the game the floats got a lot of live bytes.
The motionblur effect can be easily replicated using a simple double-buffering trick, instead of applying some blur filter on all things.
E.g.
- Use a single graphics context that all these items will be rendered into.
- Fill the graphics context with a (e.g.) 10% translucent black color
- Draw all the objects onto the graphics context
- Display results
- Go to step 2 and repeat.
For every iteration of the game loop the previous screen is darkened by 10%, mimicking the motion blur effect.