Recommended Posts

Actually it's 2 Questions,
1) What are the pros and cons with using a BufferedStrategy over double buffering using an image and graphics?
2)And can anyone point me to a tutorial/article or explain to me how to display graphics in depth? I've read some books on game programming but they seemed out dated because they used regular Image objs and Graphic objs but when i studied some code people use BufferedImage and Graphics2D.
To be more specific I'm writing this game as an Application (extends JFrame of course) and graphics is really my only problem.

Share this post

Link to post

Share on other sites

1)Here is a good article talking about using BltBufferStategy and FlipBufferStategyClicky

I would recommend using Flip. It doesn't copy the data to the main buffer it simply switches the pointer to the buffer where the image is stored. The only place I would see a Blt buffer to be usefull would be if you only update portions of screen instead of redrawing the whole screen.

2)
I am still unsure what you mean by display graphics in depth. If you mean making one object appear on top of another than I would recommend building/using a scene graph. You should be able to google around to find more information about a 2d scene graph be it basically works like this.

The basic idea of a scene works like this.

You have nodes. Think of a node an an object or group of objects in a scene. A node stores a position and possibly rotation and scaling attributes. Each node can have any number of children. To build a game scene you create what is called the root node add other nodes as children nodes to it. When you move a parent node all children nodes move with it. This makes it fairly easy to add a hat/glasses/guns to characters in the scene.

Coming back to your question on depth.

You can control the depth by adding what is called a z-index to each node. When you want to draw the scene you simply draw the root node. The root node will first draw all of it's children that have a negative z index in ascending order. Draw itself, with many nodes there may be nothing drawn. Then draw the rest of the nodes continuing in ascending order.

So to implement this you would probably start with a Node object. The Node class itself doesn't actually draw anything, but you subclass the Node object with a class such as Sprite that would actually draw.

An example of a scene graph layout.
Node - this is the root node
Sprite - this is a zombie
Sprite - this is the player
Sprite - this is the players gun
Sprite - this is a bullet
...

I just dumped out a bunch of information so if there is anything that is unclear let me know and I will try to elaborate.