Solved

Get animation to not blit

Posted on 1997-07-31
4
174 Views
Last Modified: 2010-04-04
I have a TBitmap (Bitmap1) that I move around a TForm (Form1).

I use a TTimer (Timer1) to control the move of Bitmap1 and the repaint of the Form1. The only things I do in the OnTimer-event of Timer1 is to change the variabels that defines the position of Bitmap1 and afterward call the Repaint-methode of the Form1:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if X < 200 then X := X + 1
  else X := 0;
  Form1.RePaint;
end;

I then have a OnPaint-event connected to Form1. I makes sure that Bitmap1 is drawn onto Form1's canvas before repainting:

procedure TForm1.FormPaint(Sender: TObject);
begin
  Canvas.Draw(X,Y,Bitmap1);
end;

I all works fine, but the updating of Form1 makes it blink. I guess it is because vertical retrace is not going on when I repaint my Form1.

Is there a way to wait for vertical retrace before repainting or can any of you help me lose the blinking in some way?

Thanx - Steff
0
Comment
Question by:steff
  • 2
  • 2
4 Comments
 

Accepted Solution

by:
jorgen.hojdmo earned 60 total points
ID: 1340229
Hi!

In the miserable world of eventcontrolled programming it is a bit difficulty to access such harwaredependent things. I do not say that it's impossible, but rather complicated. I would recommend you to do a doublebuffered repaint. That is: You create a bitmap the same size of the form. Draw your bitmap onto the new bitmap. Then you draw the new bitmap onto the form. Finaly you clear the new bitmap to prepare it for next paint. The blinking occures because the form has to be cleared before the bitmap can be drawn at its new position.

0
 

Author Comment

by:steff
ID: 1340230
I dont understand what the differens is between drawing my bitmap directly onto the form and drawing mt bitmap onto anther bitmap and then draw this other bitmap onto the form.
Both ways I have to draw a bitmap onto the form eevery frame and I dont thing that the form care if the bitmap that is drawn onto it is called bitmap1 og bitmap2.
Please be alittle more specific about why the blinking occures so even I can understand it!   :-)

Thanx - Steff
0
 

Expert Comment

by:jorgen.hojdmo
ID: 1340231
I'm sorry. What i forgot to tell you is that Repaint always clears the canvas before it paints anything new. Therefore you should not use repaint for smoth animations, but only to make it possible for windows to use it to keep the desktop tidy. The following example shows what i mean.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
        x,y: Integer;
        Cache,Bitmap: TBitmap;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Bitmap := TBitmap.Create;
  Cache := TBitmap.Create;
  Cache.Width := Width;
  Cache.Height := Height;
  Bitmap.LoadFromFile('handshak.bmp');
  Cache.Palette := Bitmap.Palette;
  X := 0;
  Y := 10;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Bitmap.Free;
  Cache.Free;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if X < 200 then X := X + 1
  else X := 0;
  Cache.Canvas.Rectangle(0,0, width, height);
  Cache.Canvas.Draw(x,y,bitmap);
  Form1.Canvas.Draw(0,0,Cache);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  Form1.Canvas.Draw(0,0,Cache);
end;

end.

0
 

Author Comment

by:steff
ID: 1340232
OK!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now