Reputation: 250
What is the faster way to render 2d graphics in java. The 2 good way I've seen is Double-Buffering where you create the BufferStrategy like:
JFrame f = new JFrame();
f.setSize()
.....
createBufferStrategy(2);
The other method I've seen is with the createImage method.
Image dbimage = createImage(....);
Graphics g = dbimage.getGraphics();
....
Those are the two I've seen. Which is the fastest? Are there better ways? Please don't tell me to get add-on libraries because I'm aware those exist. Thank you in advance...
Upvotes: 2
Views: 1591
Reputation: 1531
The first snippet [BufferStrategy] is the fastest and the recommended way of doing 2d rendering in java. With it you can take advantage of hardware rendering or optimized software rendering. The performance is highly noticeable when you are doing fullscreen 2d rendering. For example, you could benefit from page flipping that updates the screen by a very simple operation consisting of changing a pointer to a buffer. Other benefit is to have buffers in video memory.
Upvotes: 4