Original Post
Howdy Guys, this is my first post here although probably not the last. I have begun writing a 2D game engine in pure java. It is being written from scratch as I am doing it for a class at school, and so far I've gotten some good subcomponents completed, and am now moving to graphics. Now I've tried to implement buffered drawing to reduce flickering as well as have per-pixel capabilities, however I have very extreme flickering that has to be done through the game update loop (making the thread sleep for a second makes the flickers spread to a second, having it run as fast as possible makes the screen almost black by comparison). Here is the code for my GraphicsDriver class: ============================================== package altercation.graphics; import java.awt.*; import java.awt.image.MemoryImageSource; import altercation.core.*; import altercation.engine.*; // Basic pure java double buffered renderer public class GraphicsDriver implements Driver { private Engine engine; private GraphicsEnvironment gEnv; private GraphicsDevice gDev; private int pixels[]; private MemoryImageSource memImage; private Image image; public GraphicsDriver( Engine engine ) { this.engine = engine; gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment(); gDev = gEnv.getDefaultScreenDevice(); pixels = new int[640*480]; memImage = new MemoryImageSource( 640, 480, pixels, 0, 640 ); // TODO: Perhaps make source resizeable memImage.setAnimated( true ); memImage.setFullBufferUpdates( true ); image = Toolkit.getDefaultToolkit().createImage( memImage ); for( int i = 0;i < 640*480;i++ ) pixels = 0xff0000ff; } public void init() { } public void runFrame( Graphics g ) { memImage.newPixels(); g.setColor( Color.black ); g.fillRect( 0, 0, 640, 480 ); g.drawImage( image,0,0,null); } } ============================================== runFrame is called from the Engine classes runFrame method, which in turn is called from the application cores update loop. for testing it merely puts a blue hue onto the entire image source and draws to the screen. Hopefully you guys could help me out with this. I tried looking in the GameFrame code for clues but its so advanced it was nearly impossible to look around. I've looked at several different tutorials but im probably missing like 1 or 2 lines of code i bet. Thanks, Josh Coyne