Jump to content
  • Advertisement
Sign in to follow this  
Istarnion

Java components

This topic is 1089 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been using the Java2D API quite extensively, and haven't met any big performance barriers when making small games, so I'll keep using it for prototypes at least. Anyway, the way I do it is by having a JFrame from swing, ask it to ignore repaint, then create a Canvas, ask it the same and have manual double buffering with BufferStrategies. I do it this way because I thought this was best practice for games, and it gave you the best performance and most control. However, on Stack Overflow, this use of Canvas is criticized, and people say that using JPanel is better and Canvas is practically deprecated.
I wondered, is this true for game dev or just 'normal' GUI dev? I mean, both approaches obviously works, I've made stuff both ways, and the Canvas/BufferStrategy way feels better, but I haven't done any benchmarking. Has anyone else run some tests? I'd be interested to hear if anyone else knows more about this.

Share this post


Link to post
Share on other sites
Advertisement

Here you go...

 

http://www.gamedev.net/page/resources/_/technical/general-programming/java-games-active-rendering-r2418

http://www.gamedev.net/page/resources/_/technical/general-programming/java-games-keyboard-and-mouse-r2439

 

The is no comparison.  I can get a few hundred FPS with Swing, and 10x faster with the buffer strategy.  I haven't done any benchmarks with the latest Java 8, but I don't think it's changed that much.

 

Also, checkout the source code for my book: https://github.com/TimothyWrightSoftware/Fundamental-2D-Game-Programming-With-Java

 

That will certainly help.  See my signature for the book info...

Share this post


Link to post
Share on other sites
Nice! Thanks! I've been thinking of buying your book actually.

I had the feeling that the buffer strategy would be faster.. I have just been using fixed timesteps all the time...

But thanks for clearing my doubts!
Have you experimented with where the limits of Java 2D goes? When do you think you are forced to make the move to OpenGL or similar?

Share this post


Link to post
Share on other sites


Nice! Thanks! I've been thinking of buying your book actually.

 

Well that's always nice to hear.  I haven't run any tests to see how much is too much with Java 2D.  It uses hardware acceleration behind the scenes, so it ends up being fast enough.  The problems with using it for commercial games is that other than Minecraft, there really isn't anyone using it.  

 

I still think it's the best choice for learning to make games from scratch.  I was writing a second book about C++ and SFML, so don't worry about the language so much as just learning to makes games.  They all have good and bad parts.

Share this post


Link to post
Share on other sites

Android provides a good reason to write games in Java. AFAIK it doesn't have a well-established accelerated 2D API built-in, but there are some 3rd party libraries. The most popular is probably libgdx, which is cross-platform (even supporting iOS via RoboVM and web apps via GWT). The main developer is also the author of the excellent Beginning Android Games book which I think has a lot to offer for all Java game programmers, not just for Android, and it gives an insight into how libgdx uses OpenGL (ES) for 2D rendering.

 

However, if you do want to learn OpenGL at all I'd recommend at least version 2 instead of version 1, even for 2D. Only a handful of obsolete phones don't support v2, and the principles of shader programming you'll learn with it are much more useful in the long term, and can easily be made more efficient than v1.

Share this post


Link to post
Share on other sites
Yeah, I've been using libGDX quite alot, and done som OpenGL with SDL2 and C++, both 3D and 2D.
I just like the relative simple, built in API of Java2D, probably because I've been using it for years. Ofc, libGDX is nice and simple as well, and allows for shaders wich can be useful in some cases.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!