Demonpants Software
June 6th, 2004, 01:31 AM
Full screen mode seems like it is much more of a pain in the arse than it needs to be. I am new to it, however, so this is most likely just me messing up. I have recreated Mario using Java's Swing components in a windowed mode. The game runs great, no problems, everything's good. Before putting it away as a completed project, however, I wanted to put it into full screen mode to increase performance.
THE PROBLEM:
*****
I have never put anything into full screen mode before, and, needless to say, I have hit a few snags. I've looked everywhere, but all the tutorials I can find have incomplete answers, examples, or whatever, to the point that I just can't get it all to work correctly. I have put the game into full screen no problem - that was easy - but I can't figure out how to make the program sync with the refresh rate like the Swing repaint() method does automatically. Therefore, I get painful flickering, and everything runs slow.
I tinkered around with things and have made a few discoveries.
The setIgnoresRepaint(boolean) method didn't seem to work. Everything continued to repaint(). I manually commented out my repaint() methods because of this. This made things stop displaying at all, which was not really a surprise to me as there was now nothing ever telling the program to draw itself.
So, to have it draw again, I made this mysterious "rendering loop" that is never well explained in Java's tutorials on full screen mode and doesn't make any sense to me. It creates an infinite loop that calls the paintComponent(Graphics) method I had already made for use with Swing's repaint() method. After doing this, everything started displaying, but with the exact same flickering it had before.
On a hunch, I deleted the super.paintComponent(g); call I had in my own paintComponent method, thinking that perhaps this linked to repaint() somewhere. After doing this, the screen does not flicker. However, the JPanel this method is contained in does not draw its background (easy to do manually), and it does not erase everything after it has been drawn. So it all runs smoothly, but with a black bkgd (odd? should it not be grey?) and as pictures are moved they leave their old pictures behind them.
*****
THE QUESTION:
*****
So my question is this: if there is anyone on this planet who actually knows how to adequately use a full screen mode that refreshes constantly, (as by the countles tutorials I searched I found none) tell me how I can sync things up correctly and why setIgnoreRepaint(boolean) will not work. If there isn't, then how do I get the JPanel to erase what it has already drawn, so that I can do this manually?
Thankee for reading my long message, gurus. Just want to be specific. Also, sample code would be nice.
THE PROBLEM:
*****
I have never put anything into full screen mode before, and, needless to say, I have hit a few snags. I've looked everywhere, but all the tutorials I can find have incomplete answers, examples, or whatever, to the point that I just can't get it all to work correctly. I have put the game into full screen no problem - that was easy - but I can't figure out how to make the program sync with the refresh rate like the Swing repaint() method does automatically. Therefore, I get painful flickering, and everything runs slow.
I tinkered around with things and have made a few discoveries.
The setIgnoresRepaint(boolean) method didn't seem to work. Everything continued to repaint(). I manually commented out my repaint() methods because of this. This made things stop displaying at all, which was not really a surprise to me as there was now nothing ever telling the program to draw itself.
So, to have it draw again, I made this mysterious "rendering loop" that is never well explained in Java's tutorials on full screen mode and doesn't make any sense to me. It creates an infinite loop that calls the paintComponent(Graphics) method I had already made for use with Swing's repaint() method. After doing this, everything started displaying, but with the exact same flickering it had before.
On a hunch, I deleted the super.paintComponent(g); call I had in my own paintComponent method, thinking that perhaps this linked to repaint() somewhere. After doing this, the screen does not flicker. However, the JPanel this method is contained in does not draw its background (easy to do manually), and it does not erase everything after it has been drawn. So it all runs smoothly, but with a black bkgd (odd? should it not be grey?) and as pictures are moved they leave their old pictures behind them.
*****
THE QUESTION:
*****
So my question is this: if there is anyone on this planet who actually knows how to adequately use a full screen mode that refreshes constantly, (as by the countles tutorials I searched I found none) tell me how I can sync things up correctly and why setIgnoreRepaint(boolean) will not work. If there isn't, then how do I get the JPanel to erase what it has already drawn, so that I can do this manually?
Thankee for reading my long message, gurus. Just want to be specific. Also, sample code would be nice.