Should I be using java.awt for games?

Admittedly I’m pretty ignorant of the inner workings of Swing and AWT, but I’m going to take a bit of convincing that the “JComponent is just like Canvas+BufferStrategy but easier to use” argument is sound.

How are you triggering the buffer-flip for the JComponent? Through repaint()?

Yeah I know, not quite active rendering. Which is why it’s good for beginners. ;D

Good for beginners who like to debug synchronization glitches between the game thread and the paint (EDT) thread. ::slight_smile:

Check out the tutorial section.

This is a template to get you started right away.

It use a frame + a canvas. (well in the example it’s JFrame I know that people above told you it’s not recommended but it doesn’t make any difference really).

I actually disagree. If you don’t know how to use Java2D correctly so it isn’t hardware accelerated, it is incredibly slow.

For what it’s worth, there shouldn’t be any synchronization issues if you use a javax.swing.Timer to handle your updates, as it’s called on the EDT.

What do you mean, “use Java2D correctly?” Do you mean things like “use Canvas/BufferStrategy for page flipping” and “create compatible images, stuff like ImageIO creates non-accelerated images”? If so then I guess you’re right - that’s not stuff a beginner would know, without having sources such as this forum. :slight_smile: And it sucks that it’s an API where there’s many ways to do the same thing, some just yield slower results than others.

I still feel like, once you know a couple of basic pointers like those, most common sprite-based games (i.e., stuff a beginner should probably start with) can generally run on any hardware made in the past several years.

I do not recommend using Timer at all. It has many problems that can affect the performance of your game. I have done extensive testing and found that making your own loop is more efficient.