how to make a drawing buffer in java
I'm new to java. and I want to create a game like snake. Ho开发者_StackOverfloww can I make a drawing buffer java, where I can draw all the images? Like the background images, the objects such as the snake, etc.
Please advise.
Many thanks.
you have to look at official tutorials 2D Graphics and Performing Custom Painting, tons of examples here
You can use a BufferedImage
if CPU-based drawing is good enough for you. Rendering using BufferedImage
is pretty easy by utilizing the Graphics2D
class.
However, if you need full graphics acceleration, then I would suggest looking into some OpenGl binding for java, like JOGL or LWGL, or maybe even Java3D. I'm not personally familiar with these technologies, but from what I understand, they are all pretty popular portals for game programming in Java.
The exact term you are looking for is "canvas".
Here is an example: http://www.java2s.com/Code/Java/2D-Graphics-GUI/Drawcanvaswithcolorandtext.htm
精彩评论