Results 1 to 4 of 4
  1. #1
    bluecora is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default [Problem] JApplet image blink

    Hi, I've being trying to make a Java game and now the images are blinking too much because of the overuse of the repaint(). I tried to solve this using a buffer 1 and 2 but the problem remains.

    i use this:
    Java Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.lang.Math;
    
    public class Backbuffer2 extends Applet
       implements MouseMotionListener {
    
       int width, height;
       Image img;
       Image backbuffer;
       Graphics backg;
    
       public void init() {
          width = getSize().width;
          height = getSize().height;
    
    
          img = getImage(getDocumentBase(), "fractal.gif");
    
          backbuffer = createImage( width, height );
          backg = backbuffer.getGraphics();
         
    
         
       }
    
       public void mouseMoved( MouseEvent e ) {
    
    
    
    
          repaint();
         
       }
    
       public void update( Graphics g ) {
          g.drawImage( backbuffer, 0, 0, this );
       }
    
       public void paint( Graphics g ) {
          update( g );
       }
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,932
    Rep Power
    8

    Default Re: [Problem] JApplet image blink

    ...why don't you just call the repaint() method less? In fact, why do you need to call it at all? What's actually changing?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    bluecora is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Re: [Problem] JApplet image blink

    i have a animation always moving , if i dont loop repaint() the images dont load

    Java Code:
    		while (running) {
    			
    			timePassed = System.currentTimeMillis() - cumTime;
    			cumTime+=timePassed;
    
    			
    			updateMove(timePassed);
    			updatePrisao( timePassed);
    			preso1.update(timePassed);
    			preso2.update(timePassed);
    			preso3.update(timePassed);
    			preso4.update(timePassed);
    			repaint();
    			
    	        
    			
    			try {
    				Thread.sleep(20);
    			} catch (InterruptedException e) {
    				e.printStackTrace();
    			}

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,932
    Rep Power
    8

    Default Re: [Problem] JApplet image blink

    What thread is that being called on? You should never call sleep() on the EDT, but you should do all painting and ui-related stuff on the EDT.

    Make sure that's the case, and if you're still confused, I suggest throwing together an SSCCE that demonstrates the exact problem- basically just add an actual game loop and a single moving image to the first example you had.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. JApplet background image
    By footballHunter in forum Advanced Java
    Replies: 1
    Last Post: 11-24-2010, 02:46 AM
  2. JApplet background image
    By footballHunter in forum New To Java
    Replies: 1
    Last Post: 11-24-2010, 02:46 AM
  3. Japplet.getImage(): What if image file does not exist?
    By CoderMan in forum Java Applets
    Replies: 0
    Last Post: 02-11-2010, 11:31 PM
  4. Making text blink in a JPanel?
    By blackcloud72 in forum New To Java
    Replies: 8
    Last Post: 10-31-2008, 11:24 PM
  5. How to display an image in JApplet
    By fred in forum Java Applets
    Replies: 1
    Last Post: 07-24-2007, 02:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •