Hi again!
I’d like to thank trembovetski for helping me with my last post. I finally got it working.
But when I try to draw in my canvas, nothing works (this is with 2 buffers). However, when I use 1 buffer it seems to work…Heres the code:
//initialize the graphics when i create the canvas
public void initializeGraphics()
{
this.createBufferStrategy(this.numBuffers);
this.bufferStrategy = this.getBufferStrategy();
}
//draw the graphics on the canvas...called from a render loop
private void drawGraphics()
{
try
{ Graphics2D g2 = (Graphics2D) this.bufferStrategy.getDrawGraphics();
this.render(g2);
this.bufferStrategy.show();
g2.dispose();
} catch (Exception e)
{ System.out.println("ERROR DRAWING GRAPHICS: " + e.toString());
}
}
the render(g2) method simply uses g2 to draw some rectangles.
Now, when I initialize the graphics and call
this.createBufferStrategy(this.numBuffers)
and
this.numBuffers = 2
, nothing works (ie. the canvas is visible b/c I can see the background I set the canvas to display), but the canvas doesn’t draw anything. However, when I set
this.numBuffers = 1
, then the canvas draws everything I want it too (albiet it flickers ALOT). I’m assuming it flickers b/c there is only 1 buffer, and I’m drawing over the buffer everytime I call the render(g2) method.
Does anyone know how I would get 2 buffers to work?
Thanks for all your help!
Sincerely,
Jarrett
aka. Chisser98