Results 1 to 4 of 4
Thread: [Problem] JApplet image blink
- 06-20-2012, 04:54 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 3
- Rep Power
- 0
[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 ); } }
- 06-20-2012, 05:03 PM #2
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!
- 06-20-2012, 05:19 PM #3
Member
- Join Date
- Jun 2012
- Posts
- 3
- Rep Power
- 0
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(); }
- 06-20-2012, 05:24 PM #4
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
-
JApplet background image
By footballHunter in forum Advanced JavaReplies: 1Last Post: 11-24-2010, 02:46 AM -
JApplet background image
By footballHunter in forum New To JavaReplies: 1Last Post: 11-24-2010, 02:46 AM -
Japplet.getImage(): What if image file does not exist?
By CoderMan in forum Java AppletsReplies: 0Last Post: 02-11-2010, 11:31 PM -
Making text blink in a JPanel?
By blackcloud72 in forum New To JavaReplies: 8Last Post: 10-31-2008, 11:24 PM -
How to display an image in JApplet
By fred in forum Java AppletsReplies: 1Last Post: 07-24-2007, 02:02 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks