Java 2D Drawing Optimal Performance

前端 未结 9 1925
我寻月下人不归
我寻月下人不归 2020-12-04 09:46

I\'m in the process of writing a Java 2D game. I\'m using the built-in Java 2D drawing libraries, drawing on a Graphics2D I acquire from a BufferStrategy from a Canvas in a

9条回答
  •  甜味超标
    2020-12-04 10:38

    There's an important one which hasn't been mentioned yet, I think: cache images of everything you can. If you have an object that is moving across the screen, and it's appearance doesn't change much, draw it to an image and then render the image to the screen in a new position each frame. Do that even if the object is a very simple one - you might be surprised at how much time you save. Rendering a bitmap is much faster than rendering primitives.

    You might also want to look at setting rendering hints explicitly, and turning off things like antialiasing if quality considerations permit.

提交回复
热议问题