PDA

View Full Version : DelphiX question, help needed :-)



Wizard
29-11-2006, 09:41 AM
Hi there,

I'm building a 2d game with Delphi 6 and DelphiX. I can't seem to get it right to have a bitmap image rotating.

Here's my code for the Disk that's supposed to rotate:


// This is the Disk class
TDisk = class(TImageSprite)
private
public
Disk_Type : Word;
constructor Create(AParent: TSprite); override;
destructor Destroy; override;
procedure DoMove(MoveCount: Integer); override;

end;


// Disk Appearance table
TSpriteClass = class of TSprite;

TDiskAdvent = record
Disk_Class: TSpriteClass;
Disk_Type : Word;
StartPos_X : Integer;
StartPos_Y : Integer;
end;


const
DiskAdventTable: Array[1..5] of TDiskAdvent =
(
(Disk_Class: TDisk; Disk_Type: 1; StartPos_X: -20; StartPos_Y: -20),
(Disk_Class: TDisk; Disk_Type: 1; StartPos_X: -60; StartPos_Y: -80),
(Disk_Class: TDisk; Disk_Type: 1; StartPos_X: -100; StartPos_Y: -140),
(Disk_Class: TDisk; Disk_Type: 1; StartPos_X: -140; StartPos_Y: -200),
(Disk_Class: TDisk; Disk_Type: 1; StartPos_X: -180; StartPos_Y: -260));


var
Form1: TForm1;
Player: TPlayer;
Lives: Integer;
Seconds: Integer;
Enimies: Integer;
//Disks: Integer;
Bomb : TBomb;
Attacker: TAttacker;
x_corner: boolean;
y_corner: boolean;
Disk_Start_No: Word;
Disk_End_No : Word;


implementation

{$R *.DFM}
{$O+}


Constructor TDisk.Create(AParent: TSprite);
begin
inherited Create(AParent);

Image := Form1.DXImageList1.Items.Find('Disk');
Disk_Type := Form1.Disk_Type;
Width := Image.Width;
Height := Image.Height;
PixelCheck := True;
AnimCount := Image.PatternCount;
AnimLooped:= True;
AnimSpeed:= 15/1000;
end;

destructor TDisk.Destroy;
begin
inherited Destroy;
end;


procedure TForm1.NewDisk;
var
Disk : TSprite;
I : Integer;
begin
Form1.Disk_No:= 0;

for I:= Disk_Start_No to Disk_End_No do
begin
Disk_No:= form1.Disk_No + 1;
Disk_Type := DiskAdventTable[I].Disk_Type;
with DiskAdventTable[I] do
begin
Disk := Disk_Class.Create(Form1.DXSpriteEngine1.Engine);
Disk.X:= random (600);
Disk.Y:= StartPos_Y;
Disk.Z:= 3;
end;
end;
end;



procedure TDisk.DoMove(MoveCount: integer);
begin
inherited DoMove(MoveCount);

if X >= Form1.DXDraw1.Width - Width then X_Corner:= TRUE;
if X <10> Form1.DXDraw1.Height-100-Height then
Y&#58;= -Height;

if X_Corner = TRUE then X&#58;= X - 2;
if X_Corner = FALSE then X&#58;= X + 2;

end;


"Disk_Start_No := 1;
Disk_End_No := 1;
NewDisk;" is called in the DXTimer event handler.


Thank you for your help.

Traveler
29-11-2006, 11:58 AM
Hi and welcome to PGD.

I've placed you code around code blocks for better readability.

As for your question. I'm not entirely sure how the disc is supposed to rotate. Your code suggests the rotation is just an animation and not a programmed effect.

At first sight the code looks okay. Have you entered the patternheight and -width in the dximagelist correctly?
It could be that you need to initialize the AnimPos property.

In any case there's a demo that came with delphix in the Samples\Sprite\Shoot directory that might give you a few hints.

Wizard
29-11-2006, 12:37 PM
Thanks for your reply, I have entered the pattern height and pattern width in the object inspector and tried animpos but it makes no difference.

I now changed the animspeed to 2 and it works, the disk is turning :-)

The only problem now is that I have a lot of spinning disks and I only need one at a time.

Thanks again :-)

Wizard
29-11-2006, 01:10 PM
I got it, I needed to hit myself on the head first :-)

The disk is now spinning and only one appears at a time but it leaves behind a trail or something that stays on the screen.

Any suggestions?

Traveler
29-11-2006, 02:51 PM
Do you have a dxdraw1.surface.fill(0) at the start of your game loop?
It basically clears the screen each frame before everything gets drawn again.

WILL
29-11-2006, 03:00 PM
Hi and welcome to PGD, Wizard! :)

As an alternative to the Fill(); function you can also draw a fullscreen background image aswell. Well going down that road, you can even fill the screen with tiles instead aswell.

Lots of options really, just so long as you 'clear' or draw over everything that you don't want displayed in the next frame in each loop.

You'll get the hang of it after sometime. ;)

Wizard
30-11-2006, 08:05 AM
Thanks Traveler and Will, I appreciate your help.

I still have a lot to learn but I love every second of it :-)

Traveler
30-11-2006, 08:35 AM
No problem at all :)