Java 2D Programming

Started by
3 comments, last by Glass_Knife 10 years, 11 months ago

I would really like some help on this i just refreshed my memory in Java. I just want to know how to program 2D games in java now so if you know a great tutorial please tell me cause i have been searching and i can't find any good ones that explain the code and stuff like that it would be very helpful. Thanks.

Advertisement

Generally you're going to be setting up a game loop. Then in that game loop you're going to be updating everything, drawing everything on a buffer image, and then drawing that image onto the screen.

The game loop is just a purposeful infinite loop that manages timing and forces itself to "pause" so that the java thread scheduler can let other threads like controls(key/mouse input) and drawing the screen to run. Your game loop also needs to be the absolute boss, so things like a player pressing keys need to be a "request" if it happens outside the game loop. That logic will make it a bit easier to track down bugs since you won't have a key control event happening in the middle of your gameloop/logic processing.

You're drawing on a buffer image to save a little bit of time. Essentially the process of drawing on an image in RAM takes a lot less CPU time than drawing on the screen. Also with the wrong threading drawing straight onto the screen means the player could see the screen blip with half the objects drawn.

http://www.cokeandcode.com/index.html?page=tutorials

http://www.java-gaming.org/topics/game-loops/24220/view.html\

http://www.java-gaming.org/topics/basic-game/21919/view.html

http://www.codeproject.com/Articles/2136/Double-buffer-in-standard-Java-AWT

http://www.apl.jhu.edu/Notes/LMBrown/courses/605-481/notes/Concurrent-Programming/Double-Buffer-Example.html

Thank You so much this is very very helpful.

Many 2D games developed with Java these days are using libgdx rather than the Java2D API. It provides a more game-centric API, particularly shader-driven renderers for core OpenGL and OpenGLES, has other utilities that a game developer might need, and avoids many of the issues that crop up when distributing Java2D-based games. Further, it allows for distribution across platforms other than the standard targets (Mac,Windows,Linus), such as Android, iOS and also the browser (via javascript/HTML5 & webgl) without much effort. I would strongly recommend libgdx over Java2D for most games.

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

Enjoy!

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532

This topic is closed to new replies.

Advertisement