Solved

Get animation to not blit

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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