Delphi 经典游戏程序设计40例 的学习 1
2021年11月20日
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, ExtCtrls; type TRei40_01 = class(TForm) img1: TImage; img2: TImage; tmr1: TTimer; procedure FormCreate(Sender: TObject); procedure tmr1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end; var Rei40_01: TRei40_01; Xadd : ShortInt =1; Yadd : ShortInt =1; implementation {$R *.dfm} procedure TRei40_01.FormCreate(Sender: TObject); begin Rei40_01.Width :=640; Rei40_01.Height :=480; img1.Height := 432; img1.Width := 592; img1.Left := (ClientWidth-img1.Width) div 2; img1.Top := (ClientHeight- img1.height) div 2; img2.Height :=32; img2.Width :=32; img2.Left :=320; img2.Top :=240 ; end; procedure TRei40_01.tmr1Timer(Sender: TObject); begin if img2.Left <= img1.Left then Xadd :=1 else if img2.Left + img2.Width >= img1.Left + img1.Width then Xadd :=-1; if img2.Top <= img1.Top then Yadd :=1 else if img2.Top + img2.Height >= img1.Top + img1.Height then Yadd :=-1; img2.Left := img2.Left + Xadd; img2.Top :=img2.Top + Yadd; end; end.
一个简单的程序,
学习到的 IMAGE 组件 属性的简单设置 ,加载 图片,图标。
图片居中放置 的算法。