I am having problems with the bufferstrategy, and I do not know why. The code compiles and works, mas the performence it’s much wort than if i do not user buferstrategy. I am gonna pass part of the code, in hope somo of you guys find a mistake. Tankz.
Here I try to get a good GC
/******* init code *****/
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Arena a = new Arena(gc);
(...)
Arena is a Component that draws all my map and actors. It extends canvas and it’s in the paint method that she paint’s all the stuff. In Arena ctor, I call super(gc);
On the other hand I have a thread that sleeps for a while and then calls repaint(from Agenda).
/***************** where i use buffering ******/
public void paint( Graphics g )
{
if(firstTime) {
createBufferStrategy(2);
bufferStrategy = getBufferStrategy();
firstTime=false;
}
Graphics graphics = bufferStrategy.getDrawGraphics();
if( bufferStrategy.contentsLost() )
return;
try {
for( int i = 0; i < vTiles; ++i ) {
for( int j = 0; j < hTiles; ++j ) {
if( g.getClipBounds().intersects(terrain[i][j].getRectangle()) ) {
terrain[i][j].paint(graphics);
}
}
}
m.paint(graphics);
} finally {
graphics.dispose();
}
bufferStrategy.show();
}
What am I doind wrong? Thankz for any help guys.
[]