I'm working on a little game for learning purposes so please don't recommend me to use any library like libgdx or slickutils.

I have just one simple question. Does rendering bigger images with Graphits.drawImage(); slow the Process down?

I'm currently drawing about 200 little Objects (PNG, 64x64 resized to 48x48), but they don't seem to be an issue (i know resizing them each frame is not very performant).

The game slows down as soon as I draw the background with a parallax effect (several layers and at least 3 seamless fitting objects per layer).

They Art drawn in their original size 900x900 Pixel. But they keep slowing the game down. It's only the graphisch.drawImage(); Part. The Rest of the calculation doesn't seem to affect the game at all.

I store all Images I need once when starting the game in a class called Resources in BufferedImages.

I hope someone can explain this to me.

  • \$\begingroup\$ Of course drawing big textures will slow down - especially when you're using Graphics2D (I believe that's what it's called?). You have to render a bigger surface which will take longer than rendering a smaller surface. \$\endgroup\$ – Charanor Aug 7 '16 at 3:12
  • \$\begingroup\$ Yeah but i wanted to know if it's that much of a performance problem with Graphics2D, because rendering 1000x1000 1x1 images seems faster than rendering an 1000x1000 Images once. \$\endgroup\$ – FlaverBeat Aug 7 '16 at 3:22
  • 1
    \$\begingroup\$ Read jhlabs.com, it contains a lot of pitfalls one can fall into with java graphics. Without seeing your actual code, it is hard to pinpoint where your perfiormance problems come from. But no, generally speaking, there is no slowdown. I wrote a project using a fullscreen sized JPAnel and painted on it, and everything worked fine. Do you use double (or triple) buffering? \$\endgroup\$ – Polygnome Aug 7 '16 at 15:48
  • \$\begingroup\$ I do use double buffering. I'll upload my code later. \$\endgroup\$ – FlaverBeat Aug 7 '16 at 17:07
  • \$\begingroup\$ It would be necessary to know 1. how you are creating this 1000x1000 image and 2. what you are doing with this image (except for painting it). The crucial point is to keep the image "trackable" (i.e. in video memory), and there are many subtle ways how this trackability can be destroyed. When done properly, painting a 1000x1000 image repeatedly should take few micro(!)seconds. \$\endgroup\$ – Marco13 Aug 7 '16 at 17:42

I haven't seen your code, but likely it may be that you should render the background separately and only update it when it changes, not on every frame.

Check out this related q&a on stack overflow, it discusses performance issues with Graphics2D. The code in that answer renders the background separately. It also mentions using a BufferStrategy.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.