Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Java] Repaint is flickering

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Sun Aug 08, 2010 10:16 am    Post subject: [Java] Repaint is flickering Reply with quote

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
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Sun Aug 08, 2010 4:08 pm    Post subject: Reply with quote

Show us the code.
Back to top
View user's profile Send private message
Cheat Engine User
Something epic
Ban
Reputation: 60

Joined: 22 Jun 2007
Posts: 2071

PostPosted: Sun Aug 08, 2010 4:22 pm    Post subject: Reply with quote

http://en.wikipedia.org/wiki/Multiple_buffering
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Aug 08, 2010 7:48 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Jorg hi
I post too much
Reputation: 7

Joined: 24 Dec 2007
Posts: 2276
Location: Minnesota

PostPosted: Sun Aug 08, 2010 8:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Aug 11, 2010 9:45 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Mon Aug 16, 2010 4:28 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites