Sign in to follow this  

[java] Java fullscreen game problems

This topic is 4748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I have this sourcecode: import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.awt.image.*; public class ProjectV2 extends Frame { private Image dbImage; private Graphics dbg; int xpos=100; Button knopje; Thread th; Image kolenwagon = Toolkit.getDefaultToolkit().getImage("kolenwagon.jpg"); Image rails = Toolkit.getDefaultToolkit().getImage("rails.jpg"); public static void main(String[] args) { ProjectV2 projectV2 = new ProjectV2(); projectV2.mainloop(); } public ProjectV2() { GraphicsDevice myDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); DisplayMode oldMode = myDevice.getDisplayMode(); DisplayMode newMode = new DisplayMode(1024, 768, 32, oldMode.getRefreshRate()); if(myDevice.isFullScreenSupported()) { try { this.setVisible(false); this.dispose(); this.setUndecorated(true); myDevice.setFullScreenWindow(this); myDevice.setDisplayMode(newMode); } catch (Exception e) { myDevice.setDisplayMode(oldMode); } } else { System.out.println("Sorry No Fullscreen"); System.exit(0); } requestFocus(); Button knopje = new Button("knoopje"); knopje.setBounds(200,200,200,200); knopje.setVisible(true); //add(knopje); } /** Doublebuffer */ public void update( Graphics g ) { if( dbImage == null ) { dbImage = createImage( this.getSize().width, this.getSize().height ); dbg = dbImage.getGraphics(); } dbg.setColor( getBackground () ); dbg.fillRect( 0, 0, this.getSize().width, this.getSize().height ); dbg.setColor( getForeground() ); paint( dbg ); g.drawImage( dbImage, 0, 0, this ); } public void paint(Graphics g) { g.drawString("Hello World", 100, 100); g.drawImage(rails,200, 200,this); g.drawImage(kolenwagon,xpos, 100,this); } public void mainloop () { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); while (true) { xpos+=1; repaint(); try { Thread.sleep (100); } catch (InterruptedException ex) { } Thread.currentThread().setPriority(Thread.MAX_PRIORITY); } } } is it right that it takes a while for the images to load? My PC is pretty fast. But it takes a while for the images to load it seems. Sometimes when I click right at the start it suddenly appears. Like it needs a focus or something. What I also think is strange is the fact that i cant see my button (i disabled it now). When you click the button it will appear and right after that it disappears. very fast. Edit: The first picture loads right away, but the second one only appears later. [Edited by - beethoven_425 on December 15, 2004 4:23:02 PM]

Share this post


Link to post
Share on other sites
That is not how you implement a double buffer. Your problem lies there, you're doing too much operations in your update and paint methods. You should only create the buffer graphics once, draw to it, and in the update method just blit that to the screen.
Hope that's of help, didn't feel like going through your code line by line or rewrite it.

Share this post


Link to post
Share on other sites

This topic is 4748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this