主题:[讨论]怎样才能实现更好的效果,移动的时候应该不要出现闪屏,转弯的时候不要出现太大的时间落差?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,math;
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Button2: TButton;
Timer1: TTimer;
Timer2: TTimer;
procedure RotateImage;
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
BitMap:TBitMap;
a,b:integer;
implementation
{$R *.dfm}
procedure TForm1.RotateImage;
var x,y : Integer;
TmpBitMap : TBitmap;
begin
TmpBitMap := TBitmap.Create;
try
TmpBitMap.Assign(Image1.Picture.Graphic); //Copies a new bitmap image to the bitmap object.用graphic也行
with Image1 do begin
Picture.Bitmap.Height := TmpBitMap.Width;
Picture.Bitmap.Width := TmpBitMap.Height;
for x:=0 to Height do
for y:=0 to Width do
Canvas.Pixels[x,TmpBitMap.Width-y] := TmpBitMap.Canvas.Pixels[y,x];//TmpBitMap.Height- x代表右转
Height := TmpBitMap.Width;
Width := TmpBitMap.Height;
end;
finally
TmpBitMap.Free;
end;
end;
procedure CarMoveX(x, y: integer; Bit: TBitMap);
begin
Form1.Canvas.Draw(x, y, Bit);
//x := x + 5;
end;
procedure CarMoveY(x, y: integer; Bit: TBitMap);
begin
Form1.Canvas.Draw(x, y, Bit);
//y := y + 2;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled:=False;
RotateImage;
Timer2.Enabled:=True;
Image1.Visible:=False;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Form1.Canvas.Refresh;
Form1.Repaint;
CarMoveY(0,a,Image1.Picture.Bitmap);//沿Y轴移动
a:=a+2;
Image1.Visible:=false;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
Form1.Canvas.Refresh;
Form1.Repaint;
CarMoveX(b,a,Image1.Picture.Bitmap);
b:=b+5;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.DoubleBuffered:=true;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,math;
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Button2: TButton;
Timer1: TTimer;
Timer2: TTimer;
procedure RotateImage;
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
BitMap:TBitMap;
a,b:integer;
implementation
{$R *.dfm}
procedure TForm1.RotateImage;
var x,y : Integer;
TmpBitMap : TBitmap;
begin
TmpBitMap := TBitmap.Create;
try
TmpBitMap.Assign(Image1.Picture.Graphic); //Copies a new bitmap image to the bitmap object.用graphic也行
with Image1 do begin
Picture.Bitmap.Height := TmpBitMap.Width;
Picture.Bitmap.Width := TmpBitMap.Height;
for x:=0 to Height do
for y:=0 to Width do
Canvas.Pixels[x,TmpBitMap.Width-y] := TmpBitMap.Canvas.Pixels[y,x];//TmpBitMap.Height- x代表右转
Height := TmpBitMap.Width;
Width := TmpBitMap.Height;
end;
finally
TmpBitMap.Free;
end;
end;
procedure CarMoveX(x, y: integer; Bit: TBitMap);
begin
Form1.Canvas.Draw(x, y, Bit);
//x := x + 5;
end;
procedure CarMoveY(x, y: integer; Bit: TBitMap);
begin
Form1.Canvas.Draw(x, y, Bit);
//y := y + 2;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled:=False;
RotateImage;
Timer2.Enabled:=True;
Image1.Visible:=False;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Form1.Canvas.Refresh;
Form1.Repaint;
CarMoveY(0,a,Image1.Picture.Bitmap);//沿Y轴移动
a:=a+2;
Image1.Visible:=false;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
Form1.Canvas.Refresh;
Form1.Repaint;
CarMoveX(b,a,Image1.Picture.Bitmap);
b:=b+5;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.DoubleBuffered:=true;
end;
end.