I tried to use your constructor code.
I had to move the buferstategy codes to last, because they caused the game to crash. It said something like “component must have a valid peer”.
Now the game behaves like it did before.
I draw black text and background that dont move. Those look great. The players on the field are ok. I think they flicker a bit. Not much. But the white text under the ball carrying player that indicates his name flickers like mad.
if ( ball.state == 1 || ball.state == 2 )
{
g.setColor(Color.white);
g.drawString(messageballcarrier,(int)ball.x -20,(int)ball.y + 20);
}
I started to think that maybe I am doing doublebuffermode ok, but the ball.x double to int coordinate conversion could make some flickering kind of effect?
My current constructor code:
public ThegameFrame() {
JFrame frame = new JFrame("Death Match Manager");
frame.setIgnoreRepaint( true );
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Canvas canvas = new Canvas();
canvas.setBounds(0, 0, 1024, 768);
canvas.setIgnoreRepaint(true);
// canvas.createBufferStrategy(2);
// canvas.addMouseListener(new MouseControl());
canvas.addMouseListener(this);
canvas.addKeyListener(new KeyInputHandler());
// strategy = canvas.getBufferStrategy();
JPanel panel = (JPanel) frame.getContentPane();
panel.setPreferredSize(new Dimension(1024, 768));
panel.setLayout(null);
panel.add(canvas);
frame.pack();
frame.setResizable(false);
frame.setVisible(true);
panel.setVisible(true);
canvas.setVisible(true);
canvas.requestFocus();
// nämä piti siirtää setvisiblen alle
canvas.createBufferStrategy(2);
strategy = canvas.getBufferStrategy();
//OMAAA
gamestate = 1; // 1 = Setup phase, 2 = Game on,
// score1 = 0;
// score2 = 0;
matchon = true;
for ( int i = 0; i < 8; i++)
message[i] = " ";
// add a key input system (defined below) to our canvas
// so we can respond to key pressed
// request the focus so key events come to us
// requestFocus();
Random generator = new Random();
// ALUSTETAAN DEBUGGAUS JOUKKUEET
Player player = new Player(this,"ogrelay.png",370,350,1);
player.makeOgre();
player.name = "Ogre dude";
entities.add(player);
for ( int i = 0; i < 9; i++)
{
player = new Player(this,"lay.png",generator.nextInt(300),generator.nextInt(768),1);
player.makeHuman();
entities.add(player);
player.name = "Lineman dude";
if ( i == 6)
{
player.name = "Wing dude";
player.position = 3; //WING
}
if ( i == 5)
{
player.name = "Thrower dude";
player.position = 2; //THrower
}
}
player.name = "Wing dude 2";
player.position = 3; //WING
for ( int i = 0; i < 10; i++)
{
player = new Player(this,"xlay.png",(generator.nextInt(300)+700),generator.nextInt(768),2);
player.makeHuman();
entities.add(player);
player.name = "Lineman dude";
if ( i == 6)
{
player.name = "Wing dude";
player.position = 3; //WING
}
if ( i == 5)
{
player.name = "Thrower dude";
player.position = 2; //THrower
}
}
player.name = "Wing dude 2";
player.position = 3; //WING
// container.setIgnoreRepaint(true);
// panel.setIgnoreRepaint(true);
}