0

So I need to make a simple game for a project, and the StdDraw from princeton library was provided. From looking through the source code it seems like the library handles animation by drawing on two (for double buffering) BufferedImages and then displays on on a JFrame. To increase the window size the BufferedImage is simply increased in size and the drawings scaled up. But this causes severe lag and screen tear when going above say 700x700 pixels.

I don't know enough about Java to know if this is the most efficient method of doing animation but there must be a way to animate a simple triangle fullscreen without lag. I can easily edit the library or even just write my own if someone could give me some pointers on what is the best way to handle animation.

Google drive for StdDraw.java if anyone wants to look

epep
  • 51
  • 4
  • Java provides three different libraries for drawing; AWT, Swing, and JavaFX. AWT is obsolete. Here's a simple animation example using Java Swing. https://stackoverflow.com/questions/34981403/bufferedimage-not-being-cleared-before-each-rendering/35002727#35002727 – Gilbert Le Blanc Feb 26 '20 at 16:42
  • Thanks, I tried JavaFX and it works a lot better. But theres still one thing I'm wondering about. If I set the scene to fullscreen with .setFullscreen(true) the resolution of the scene changes to that of my monitor, and renders in that resolution. Is there a way I can set a predefined resolution and then when the application goes fullscreen it just upscales instead of drawing everything in a higher resolution? – epep Mar 01 '20 at 08:59
  • Upscaling your graphics isn't going to look good. You're better off working with a large drawing area and downscaling to fit the particular monitor. – Gilbert Le Blanc Mar 01 '20 at 12:43
  • Thanks, yeah but the reason I want to upscale it is because StdDraw lags really easily. But it's fine I decided to not use StdDraw, I got it working using JavaFX and the GraphicsDevice to change the PC's display resolution, it works perfectly. – epep Mar 02 '20 at 13:16

0 Answers0