| View previous topic :: View next topic |
| Author |
Message |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
Posted: Sun Aug 08, 2010 10:16 am Post subject: [Java] Repaint is flickering |
|
|
I'm drawing a rectangle to the window and I put a repaint event on a timer set to 1 and the rectangle flickers?
_________________
CEF will always stay alive. |
|
| Back to top |
|
 |
justa_dude Grandmaster Cheater
Reputation: 23
Joined: 29 Jun 2010 Posts: 893
|
Posted: Sun Aug 08, 2010 4:08 pm Post subject: |
|
|
| Show us the code.
|
|
| Back to top |
|
 |
Cheat Engine User Something epic
Reputation: 60
Joined: 22 Jun 2007 Posts: 2071
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Aug 08, 2010 7:48 pm Post subject: |
|
|
This has been brought up a few times in the past week or so.
You are not drawing in sync with the other window, just tossing a drawing routine into a timer will not give you flicker free drawing. You need to sync your drawing with the applications refreshing. There are multiple ways of doing it, such as hooking the painting method of the target application and drawing your information afterward.
Also in the future, post more information, show code, or explain in more detail before you post. Saying 'it don't work' is not a suitable topic.
_________________
- Retired. |
|
| Back to top |
|
 |
Jorg hi I post too much
Reputation: 7
Joined: 24 Dec 2007 Posts: 2276 Location: Minnesota
|
Posted: Sun Aug 08, 2010 8:19 pm Post subject: |
|
|
Yeah I know. I solved it though by calling update(this.getGraphics) instead of using the repaint().
| Code: |
public void update(Graphics g) {
Graphics offgc;
Image offscreen = null;
Rectangle box = g.getClipRect();
// create the offscreen buffer and associated Graphics
offscreen = createImage(box.width, box.height);
offgc = offscreen.getGraphics();
// clear the exposed area
offgc.setColor(getBackground());
offgc.fillRect(0, 0, box.width, box.height);
offgc.setColor(getForeground());
// do normal redraw
offgc.translate(-box.x, -box.y);
paint(offgc);
// transfer offscreen to window
g.drawImage(offscreen, box.x, box.y, this);
}
|
_________________
CEF will always stay alive. |
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Wed Aug 11, 2010 9:45 am Post subject: |
|
|
In Java, you can create a BufferStrategy for double buffering animation. Something like this:
| Code: | BufferStrategy bufferStrategy = null;
Graphics2D g = null;
this.setIgnoreRepaint(true); // this = JFrame
try {
this.createBufferStrategy(2);
bufferStrategy = this.getBufferStrategy();
} catch (Exception e) {
e.printStackTrace();
} |
Then in animation loop:
| Code: |
g = (Graphics2D) bufferStrategy.getDrawGraphics();
// Do drawing with g.drawWhatever() and whatever else
g.dispose()
bufferStrategy.show(); |
|
|
| Back to top |
|
 |
iPromise Grandmaster Cheater
Reputation: -1
Joined: 27 Jun 2009 Posts: 529 Location: Canada
|
Posted: Mon Aug 16, 2010 4:28 am Post subject: |
|
|
| I don't code in Java, but the methods are the same. Draw on to a memory DC, then swap the memory DC to the applications DC. This is called the 'Double Buffering' technique, you can search it up and find some decent examples.
|
|
| Back to top |
|
 |
|