Jump to content
  • Advertisement
Sign in to follow this  
convey

Java 2D Programming

This topic is 2028 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 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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!