2D Game image rendering alternatives?

Hi everyone,

I got a question regarding image rendering for my 2D game.

I have read many ways of doing this but they practically they all took me to the same point. My project currently has this:

  • A class with a JFrame, with a basic game framework, starting a thread, running the game loop…
  • A class that extends JPanel, wich has the paintComponent() where i do all the painting.

Currently i just have a tile based isometric map drawn on the JPanel the problem comes that when i call repaint() within my game loop it redraws everything again (it even clears the screen if i got it right). And there are some images that i don’t feel they need to be rendered again.

So i read a lot about this and i found that i could pass parameters to repaint() so it paints only the things that i want. But i wasn’t able to pass the parameters for only drawing a determined image. Furthermore i also noticed that when i minimze or resize the window the paintComponent() method gets called again.

I feel like i’m not having the control of how my application renders so my question is, is this how it is commonly done? should i adapt to the JPanel paint or do i have an alternative? I also tried canvas and is more of the same i think?

I need to resolve this after moving on in my proyect.

Thanks in advance!

You should use openGL… It is way faster and very good i suggest using slick2D for start. Or libGDX it is way better… Using JFrame to do the rendering is not good for a game, it is for aplications buttons a
nd stuff xD !

If you really want to stick with Java2D for your rendering, then try batching your images!

If you have a world composed of tiles that you know wont change, then render all of them to a separate BufferedImage once, then draw that image to your screen instead of all the tiles. This cuts back on draw calls, which will have less of a bottleneck in your application.