Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Double Buffering ineffective?  (Read 984 times)
0 Members and 1 Guest are viewing this topic.
Offline Alfryd

Junior Member





« Posted 2005-10-23 16:00:34 »

This has got to be the oldest gripe in the book, but a friend of mine using the Java2D api has been experiencing flicker problems using the following code.  As far as I can tell it uses double-buffering correctly, and I've seen the same problems myself when I run it.  I've thrown every trick in the book I know at it, even going so far as "bufferInt = ((DataBufferInt)(buffer.getRaster().getDataBuffer())).getData();", to no avail.  Any clues as to the underlying problem would be appreciated.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
import java.awt.*; 
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;

public class ImageFrame extends JFrame implements ActionListener{
    private BufferedImage frameImg;
    private Graphics2D frameImgG;
   
    private Image plainsI, warriorI;
   
    private int xloc;
    private Timer xlocTimer;
   
    public ImageFrame() {
        super("Image testing");
       
    }
   
    public void run() {
        plainsI = Toolkit.getDefaultToolkit().getImage("Plains01.jpg");
        warriorI = Toolkit.getDefaultToolkit().getImage("Warrior.png");
       
        frameImg = new BufferedImage(800, 600,
                BufferedImage.TYPE_INT_RGB);
        frameImgG = frameImg.createGraphics();
       
        xloc = 150;
       
        xlocTimer = new Timer(200, this);
        xlocTimer.start();
       
        setSize(800, 600);
        setVisible(true);
    }
   
    public void paint(Graphics g) {
        super.paint(g);
       
        frameImgG.drawImage(plainsI, 0, 0, 800, 600, null);
       
        frameImgG.drawImage(warriorI, xloc, 400, null);
       
        g.drawImage(frameImg, 0, 0, null);
    }
   
   
    /** Respond to Timer's event */
    public void actionPerformed(ActionEvent a) {
        repaint();
        xloc+=10;
        if (xloc > 500) {
            xlocTimer.stop();
        }
       
    }
   
    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) {
       
        ImageFrame application = new ImageFrame();
        application.run();
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
    }
   
}
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #1 - Posted 2005-10-23 16:09:28 »

Why not just BufferStrategy?

With manual double buffering update() needs to be overwritten.

弾幕 ☆ @mahonnaiseblog
Offline Linuxhippy

Senior Member


Medals: 1


Java games rock!


« Reply #2 - Posted 2005-10-23 17:29:49 »

you're using a BufferedImage as BackBuffer which is done in SW only.

Use BufferStrategy or VolatileImage for hw-accerlated double buffering.

lg Clemens
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Ask_Hjorth_Larsen

Junior Member




Java games rock!


« Reply #3 - Posted 2005-10-24 05:52:43 »

If you're using repaint() instead of active rendering, why not just use the built-in swing double buffering? Also, what is the effect of overriding paint instead of paintComponent?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (11 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!