Solved

Get animation to not blit

Posted on 1997-07-31
4
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

628 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