1

I have seen at least 2 ways of displaying graphics and animating in java, for example in order to make a game. One uses the paint method, which would appear to be pretty simple. The other uses a while loop, inside of which you configure your fps, your tps (ticks per second), then you update your program's information, and finally you render the graphics.

This last way appears to have nothing to do with the paint method, so I don't understand. Are these different ways of approaching the same problem? Is there a diference? I am experimenting with game making in java (I have been for only a week or so) and this seems to be a key element, but I'm still not getting it.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • 2
    *"This last way appears to have nothing to do with the paint method, so I don't understand"* - This could be using a `BufferedStrategy` or their own buffering technique and rendering the resulting image through the normal painting system – MadProgrammer Jan 19 '17 at 22:46
  • Yes, actually I was using a BufferedStrategy, and then to render I was passing a Graphics object to a custom render() method, without using paint(). Is it just a different way of doing the same thing? – Nicolas Martorell Jan 19 '17 at 22:52
  • 1
    I'd suggest you start by having a look at [BufferStrategy and BufferCapabilities](https://docs.oracle.com/javase/tutorial/extra/fullscreen/bufferstrategy.html), [Performing Custom Painting](https://docs.oracle.com/javase/tutorial/uiswing/painting/), [Painting in AWT and Swing](http://www.oracle.com/technetwork/java/painting-140037.html) for how the two painting processes work. Basically, `BufferedStrategy` is a active painting mechanism, which gives all the control to your, Swing's painting process is a passive painting process, which is controlled by Swing – MadProgrammer Jan 19 '17 at 22:52
  • I wouldn't say it's a different way to do the same thing per say, as they are different approaches to perform painting based on your needs, for example, you can use Swing components with a `BufferedStrategy`, you might want to also have a look at [Passive vs. Active Rendering](http://docs.oracle.com/javase/tutorial/extra/fullscreen/rendering.html). You should also note that `BufferedStrategy` requires the use of a heavy weight component (`Canvas`) which may affect what you can do (the component itself doesn't support transparency for example) – MadProgrammer Jan 19 '17 at 22:57
  • And [this](http://stackoverflow.com/questions/24131513/java-what-is-heavier-canvas-or-paintcomponent/24131544#24131544) might also help :P – MadProgrammer Jan 19 '17 at 23:21
  • This really helped, thank you very much! – Nicolas Martorell Jan 19 '17 at 23:25

0 Answers0