Java Canvas Zooming in Flickering

197 Views Asked by At

I'm working on a project that requires me to be able to zoom in and out on a Canvas. I'm using the method:

setSize(new Dimension(WIDTH * scale, HEIGHT * scale));

and from there just modifying the scale variable. This works, except most of the time I will get an annoying flicker. It's triple buffered, so I don't really understand how it could take that long to transform the canvas to the proper size...

Anyway, if there's something I'm missing, I'd love to know.

Here's my update() method:

public void update() {
    updateCount++;

    if (input.mouseWheel.getNotchesMoved() != 0 && SCALE >= MIN_SCALE
            && SCALE <= MAX_SCALE) {
        SCALE += input.mouseWheel.getNotchesMoved();
        if (SCALE > MAX_SCALE)
            SCALE = MAX_SCALE;
        if (SCALE < MIN_SCALE)
            SCALE = MIN_SCALE;
        setSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
    }
    input.refresh();
}

Thanks in advance,

Tree

EDIT: When I say "Canvas", I mean java.awt.Canvas, the base class of the main class, sorry about any confusion.

0

There are 0 best solutions below