Tile-Based game [Java2D] (128x128px). FPS drops when resizing the window!

Hello fellow coders :smiley:

I have a problem with my tile-based game.
I want to make a Tile-based game with 128x128px sprites. The problem is that I only have ± 50 FPS when I try to render my tiles (at a
high resolution). My code looks quite simple but I dont know why I only have 50 FPS.
Here my Main class: http://pastebin.com/gPTknRZt
Even if I remove the level.render(…) method I still have 50FPS.
EVEN if I only draw a black screen I only have 50FPS, so I have to do something terribly wrong.
Is it good to make the image like twice as big as the window and then scale it down and render it so you can fit more tiles on the window. Or how should I re-size my image without many frame drops.

Thank you for your help.
Any help is appreciated. 8)

This looks to me like java 2d and I haven’t used that, so I’m not really sure if this helps but for me two things stand out.

  1. You dispose of the graphics object each render pass. If I’m not mistaken this causes the graphics object to get recreated evrery frame and this can be an expensive operation.
  2. You read all screen pixels in the render method. This might also be an expensive operation.

So try out if performance changes if you change those things.

Profiling might help you to find your bottleneck.

I tried everything you said but with no success…
The problem is, even if I draw just a black screen I only have 40fps, which is totally weird… I think it has something to do with the image scaling.
Because as said my image is actual bigger than my window so it have to scale it down to draw it.

There were a few problems that I noticed.

  1. You aren’t waiting in your loop at all. Please use [icode]Thread.sleep(17);[/icode] in your game loop so that you aren’t hogging the CPU.

  2. The pixels array is never used so why are you even reading the pixels?

  3. Don’t use underscores in the numbers. This makes it so that only people with Java 1.7 and higher can run your program (correct me if I’m wrong, it may just be that you can’t compile it if you have a lower version than 1.7)

  4. Why is your BufferedImage 4 times the window size? In your render method it says that it’s so you can fit more tiles on the screen!? Just make your tiles smaller!