W
wanglong
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Menus;
type
TSprite = class
public
FBits: TBitmap;
constructor Create; virtual;
end;
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
Image1: TImage;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure N1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
wl:tsprite;
//定义位置
a,b:integer;
implementation
{$R *.dfm}
constructor TSprite.Create;
begin
inherited Create;
FBits := TBitmap.Create;
FBits.Width := 100;
FBits.Height := 100;
fbits.LoadFromFile('mytank.bmp');
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=vk_up then
begin
a:=a;
b:=b-10;
image1.Canvas.FillRect(image1.Canvas.ClipRect);
image1.Canvas.Draw(a,b,wl.FBits);
end;
if key=vk_down then
begin
a:=a;
b:=b+10;
image1.Canvas.FillRect(image1.Canvas.ClipRect);
image1.Canvas.Draw(a,b,wl.FBits);
end;
if key=vk_left then
begin
a:=a-10;
b:=b;
image1.Canvas.FillRect(image1.Canvas.ClipRect);
image1.Canvas.Draw(a,b,wl.FBits);
end;
if key=vk_right then
begin
a:=a+10;
b:=b;
image1.Canvas.FillRect(image1.Canvas.ClipRect);
image1.Canvas.Draw(a,b,wl.FBits);
end;
end;
procedure TForm1.N1Click(Sender: TObject);
begin
//如何把新创建的类显示到image控件上
wl:=tsprite.Create;
iMAGE1.Canvas.Draw(0,0,wl.FBits);
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, Menus;
type
TSprite = class
public
FBits: TBitmap;
constructor Create; virtual;
end;
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
Image1: TImage;
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure N1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
wl:tsprite;
//定义位置
a,b:integer;
implementation
{$R *.dfm}
constructor TSprite.Create;
begin
inherited Create;
FBits := TBitmap.Create;
FBits.Width := 100;
FBits.Height := 100;
fbits.LoadFromFile('mytank.bmp');
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key=vk_up then
begin
a:=a;
b:=b-10;
image1.Canvas.FillRect(image1.Canvas.ClipRect);
image1.Canvas.Draw(a,b,wl.FBits);
end;
if key=vk_down then
begin
a:=a;
b:=b+10;
image1.Canvas.FillRect(image1.Canvas.ClipRect);
image1.Canvas.Draw(a,b,wl.FBits);
end;
if key=vk_left then
begin
a:=a-10;
b:=b;
image1.Canvas.FillRect(image1.Canvas.ClipRect);
image1.Canvas.Draw(a,b,wl.FBits);
end;
if key=vk_right then
begin
a:=a+10;
b:=b;
image1.Canvas.FillRect(image1.Canvas.ClipRect);
image1.Canvas.Draw(a,b,wl.FBits);
end;
end;
procedure TForm1.N1Click(Sender: TObject);
begin
//如何把新创建的类显示到image控件上
wl:=tsprite.Create;
iMAGE1.Canvas.Draw(0,0,wl.FBits);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
form1.DoubleBuffered:=true;
end;
end.