×

Discussion Board

Results 1 to 2 of 2

Hybrid View

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    48

    screen flicker during animation

    I'm writting a Java application that runs an animation. It works, but the screen flickers when drawing. Is there a way to fix this?? Someone told me I needed to use Double Buffering -- what's that??

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    41

    RE: screen flicker during animation

    The idea of the double buffering is to, first draw everything into the object of the Image-class and then flash everyting at once to the screen.

    Code example:



    Image buffer;
    Dimension size;
    Graphics bufferGraphics;
    .
    .
    .

    Constructor

    Dimension size = this.size();
    bufferImage = createImage(size.width, size.height);
    buffer = bufferImage.getGraphics();
    .
    .
    .

    public void paint(Graphics g) {


    buffer.setColor(this.getBackground());
    buffer.fillRect(0, 0, size.width, size.height);
    //"first draw everything into the object of the Image-class"


    g.drawImage(buffer, 0, 0, this);
    // flash everyting at once to the screen
    }


    public void update(Graphics g) {
    paint(g);
    }
    // Calling the "update" cleans the screen before updating, this might caused winking. Because of that it is better tocall directly "paint" for the updating.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×