This example effect chart (illustrated with a GIF animation, however, does not come with the smooth effect of DirectX):
Code files:
unit Unit1;
Interface
uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Dxdraws, Stdctrls, Dxclass;
type
TForm1 = Class (Tform)
Dxdraw1:tdxdraw;
dximagelist1:tdximagelist;
Dxtimer1:tdxtimer;
Button1:tbutton;
Button2:tbutton;
procedure formcreate (sender:tobject);
procedure Dxtimer1timer (sender:tobject; Lagcount:integer);
procedure Button1Click (sender:tobject);
procedure Button2click (sender:tobject);
end;
var
Form1:tform1;
implementation
{$R *.DFM}
var
Arr:array of record X,y,a,b:integer; End
Picitem:tpicturecollectionitem;
procedure Tform1.formcreate (sender:tobject);
Const
ImgPath1 = ' C:\Temp\DelphiX.bmp ';
begin
dxdraw1.align: = alclient;
Dximagelist1.dxdraw: = DXDRAW1;
DXImageList1.Items.Add;
Picitem: = Dximagelist1.items[dximagelist1.items.count-1];
PicItem.Picture.LoadFromFile (IMGPATH1);
SetLength (arr, 1);
Arr[0]. X: = Random (Dxdraw1.width-picitem.width);
Arr[0]. Y: = Random (dxdraw1.height-picitem.height);
arr[0].a: = 1;
arr[0].b: = 1;
button1.caption: = '-';
button2.caption: = ' + ';
Dxtimer1.interval: = 10;
end;
Procedure Tform1.button1click (Sender:tobject);
begin
if Length (arr) > 1 then SetLength (arr, Length (arr)-1);
end;
procedure Tform1.button2click (sender:tobject);
begin
SetLength (arr, Length (arr) +1);
Arr[high (arr)]. X: = Random (Dxdraw1.width-picitem.width);
Arr[high (arr)]. Y: = Random (dxdraw1.height-picitem.height);
Arr[high (arr)].a: = 1;
Arr[high (arr)].b: = 1;
end;
procedure Tform1.dxtimer1timer (sender:tobject; Lagcount:integer);
var
I:integer;
begin
DXDraw1.Surface.Fill (0);
for I: = 0 to Length (arr)-1 do
begin
if Arr[i]. X > Dxdraw1.width-picitem.width then arr[i].a: =-1;
if Arr[i]. Y > Dxdraw1.height-picitem.height then arr[i].b: =-1;
if Arr[i]. X = 0 Then arr[i].a: = 1;
if Arr[i]. Y = 0 Then arr[i].b: = 1;
Inc. (arr[i). X, ARR[I].A);
Inc. (arr[i). Y, arr[i].b);
Picitem.draw (Dxdraw1.surface, arr[i). X, Arr[i]. Y, 0);
end;
Dxdraw1.flip;
end;
end.