开发者

Java backbuffer and animations

开发者 https://www.devze.com 2023-04-12 08:25 出处:网络
I\'m creating a simple 2D game in java. I\'ve only done this in C++ with the Windows API so far. In java, I\'m getting a Graphics object by extending JFrame and calling this.getContentPane().getGraphi

I'm creating a simple 2D game in java. I've only done this in C++ with the Windows API so far. In java, I'm getting a Graphics object by extending JFrame and calling this.getContentPane().getGraphics(). With this object, I'm drawing everything to the screen, every frame. This raises a few questions:

  1. Backbuffer: I'm not getting any flickering effects, while I'm not using a backbuffer (I'm开发者_Go百科 drawing directly on the Graphics object). Why is this? Does java has a built-in backbuffer or something?

  2. Animations: I'm used to put all animation parts in a single sprite sheet, like in this example: http://www.envygames.com/share/sample_animation.jpg

Now, someone has told me that you can just draw animated .gif's and java will draw these independent of the game loop. I've tried this out and it doesn't seem to work. Is this true or am I also supposed to use these sprite sheets in java?

Thanks


Yes, Java has a double buffer rendering strategy that can be switched on and off...

Java: how to do double-buffering in Swing?

About the animated gifs, I think it is right, but you may have to put them in the appropriate container (maybe as the icon of a JLabel?).


getting a Graphics object by extending JFrame and 
calling this.getContentPane().getGraphics().

don't painting directly to the JFrame for Custom Painting you have to look for JLabel that allows painting everything, another choise will be extending JCompoments, or JPanel for that

for painting in the Swing you have to look for paintComponent(Graphics g), not paint(Graphics g), because this method are lots of time used in examples and ditributed on some of Java ExamplesDepots, that's wrong method with possible lacks

0

精彩评论

暂无评论...
验证码 换一张
取 消