I ran into a very strange problem while using BufferStrategy, I've tried searching for an answer but all I have found are non-relevant threads and discussions. So here is my query.
for (int i = 0; i < 10; i++){
for (int x = 0; x < 10; x++){
g.drawImage(enlImg(getImg(terrain, x), 4), i*40, x*40, null);
}
}
(The parameter 'terrain' is a BufferedImage pre-loaded, which will be used to get a sub image from it.)
I'm trying to draw images to a Canvas, where 'g' is the buffer strategies, 'getDrawGraphics()' because that's how I am drawing to the BufferStrategy. Anyway, straight to the point. I'm only getting ~3fps.
I know this is only drawing 100 images, but other games draw hundreds of thousands with no lag... Any ideas?
Is it maybe because of trying to enlarge, draw and get a sub image all at once, or is it because of my computer?
Extra
enlImg() code
public BufferedImage enlImg(BufferedImage image, int x){
BufferedImage enlargedImage = new BufferedImage(image.getWidth() * x, image.getHeight() * x, image.getType());
for (int a = 0; a < enlargedImage.getHeight(); a++) {
for (int b = 0; b < enlargedImage.getWidth(); b++) {
enlargedImage.setRGB(a, b, image.getRGB(a / x, b / x));
}
}
return enlargedImage;
}
getImg() code
public BufferedImage getImg(BufferedImage img, int x){
int y = 0;
if (x >= 10){
x=x-10;
y++;
}
return img.getSubimage(x*10, y*10, 10, 10);
}
Computer Specifications (Windows):
AMD Athlon II X2 250 - 3.00GHz
OS: 32bit
4GB RAM,
256GB HHD