Solved

Get animation to not blit

Posted on 1997-07-31
4
175 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
proper way to parse text with delphi 7 101
error 1.1 400 Bad request idhttp delphi 18 55
CheckListBox usage 3 51
Graphics32 under Delphi 10.1 Berlin 2 40
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

27 Experts available now in Live!

Get 1:1 Help Now