I'd like to program a 2D game engine. The problem i have (i don#t use opengl and stuff like that, so i render with cpu) is, that i only get 7fps through the graphics.drawImage(); Do you have any suggestions to speed this up or any alternatives?
image = new BufferedImage(gc.getWidth(), gc.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
canvas.createBufferStrategy(1);
bs = canvas.getBufferStrategy();
g = bs.getDrawGraphics();
g.drawImage(image, 0, 0, canvas.getWidth(), canvas.getHeight(), null);
My renderer should simply color the frame (width 320 height 240 pixels) cyan, and he does, but only at a maximum of 8fps. Renderer:
private int width, height;
private byte[] pixels;
public Renderer(GameContainer gc){
width = gc.getWidth();
height = gc.getHeight();
pixels = ((DataBufferByte)gc.getWindow().getImage().getRaster().getDataBuffer()).getData();
}
public void clear(){
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
int index = (x + y * width) * 4;
pixels[index] = (byte)255;
pixels[index+1] = (byte)255;
pixels[index+2] = (byte)255;
pixels[index+3] = 0;
}
}
}