Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User nkn_motoko's Avatar
    Join Date
    Mar 2003
    Posts
    48
    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 TheTic's Avatar
    Join Date
    Mar 2003
    Posts
    41
    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
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved