Effectivly Drawing a Real-Time Game

Hello, I have several questions regarding the methods needed to draw a real-time game. First of all, is there a way of using Hardware accelerated graphics in Java? Secondly, and more to the point, my real-time game needs to repaint the screen every 25 milliseconds. The actual painting is done in the paintComponent method of my Game component (which extends JPanel). Anyway, I need to draw the background Image and to draw the foreground image onto existing terrain. I am painting the whole Background image (clipped to the size of the screen) each repaint. Furthermore, I draw the Foreground Image once for each polygon in my Vector of Polygons which describe the terrain - each time the graphics is clipped to the current terrain polygon I am referring to. This means I draw the amount of Polygons + 1 images every 25 milliseconds (And some of which are 3000x3000 pixels big). No wonder the screen is flickering... However, I do not know any alternate way (even though I am sure one exists). Any help would be kindly appreciated.

With Thanks,

laginimaineb.

[1078 byte] By [laginimaineba] at [2007-11-27 1:35:54]
# 1
http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html
CaptainMorgan08a at 2007-7-12 0:44:45 > top of Java-index,Other Topics,Java Game Development...
# 2

@laginimaineb,

Create terrain image 'only once' using,

Image image = Toolkit.getDefaultToolkit().getImage(fileName);

BufferedImage bimage = new BufferedImage(3000,3000, type); //Max size set

Graphics g = bimage.createGraphics();

for(int i=0;i<noOfPolygons;i++) {

g.drawImage(image, xPos, yPos, null);

g.drawPolygon(polygon);

}

Image completeImage = Toolkit.getDefaultToolkit().createImage(bimage.getSource());

g.dispose();

Just draw this CompleteImage in paint() or paintComponent() method.

CompleteImage is created only once.

If you are changing terrain after 25 seconds then different logic may need.>

kanada at 2007-7-12 0:44:46 > top of Java-index,Other Topics,Java Game Development...
# 3
Thanks a lot Morgan, my game doesn't flicker at all! This is a thousand times better.With Thanks,laginimaineb.
laginimaineba at 2007-7-12 0:44:46 > top of Java-index,Other Topics,Java Game Development...