Archived

This topic is now archived and is closed to further replies.

Flare

DelphiX Sprite Engine Tutorial?

Recommended Posts

Flare    122
Does anyone know where to find a good tutorial on the DelphiX Sprite Engine and/or the usage of sprites? I''ve searched quite a lot, but I haven''t yet found what I''m looking for. Any help would be appreciated!

Share this post


Link to post
Share on other sites
Harry Hunt    542
I'm not too familiar with DelphiX, but one easy way of writing a sprite engine is this...

TMySprite = record
__X, Y: Integer;
__Health: Byte;
__{ Add more here }
end;

TSpriteArray = array of TMySprite;

...

var
__MySprites: TSpriteArray;
__I: Integer;

...

SetLength(MySprites, 5);

for I := 0 to 4 do
begin
__MySprites.X := Random(640);
__MySprites[I].Y := Random(480);
__MySprites[I].Health := 100;
end;

...

Use another "for I :=..." to draw the sprites on your screen. You can do that with the normal DelphiX drawing routines...
Add a "Frame: Integer" to your TMySprite record and increment it and change your drawing routine accordingly to animate your sprites. Might be faster than the DelphiX sprite engine, but then again I'm not too familiar with it...


[edited by - Harry Hunt on May 8, 2002 6:57:27 AM]

Share this post


Link to post
Share on other sites
Harry Hunt    542
The forum script somehow changed

MySprites [ I ].X := Random(640); into
MySprites.X := Random(640);


dunno why...


ONE THING: This example uses dynamic arrays which from what I know are not supported by any Delphi version prior to 4

[edited by - Harry Hunt on May 8, 2002 7:00:30 AM]

Share this post


Link to post
Share on other sites
Useless Hacker    372
quote:
Original post by Harry Hunt
The forum script somehow changed

MySprites [ I ].X := Random(640); into
MySprites.X := Random(640);

dunno why...

It''s ''cos the forum interprets the ''I'' tag as italics.

I don''t think he''s asking how to write his own sprite engine, he wants to know how to use the DXSpriteEngine that comes with DelphiX.

Share this post


Link to post
Share on other sites
Harry Hunt    542
thanks for the info about the italics thing...

I know that he asked about the DelphiX sprite engine...but I don''t know much about it (I don''t have DelphiX installed).
However, writing a simple sprite engine is so easy that I don''t quite get the point in using a 3rd party one.
Also, your own sprite engine would be a lot more customizable, prolly faster and it would be "your own" engine.

Share this post


Link to post
Share on other sites
Useless Hacker    372
quote:
Original post by Harry Hunt
thanks for the info about the italics thing...
My pleasure.
quote:
I know that he asked about the DelphiX sprite engine...but I don''t know much about it (I don''t have DelphiX installed).
Are you mad?? Get it!
quote:
However, writing a simple sprite engine is so easy that I don''t quite get the point in using a 3rd party one.
Also, your own sprite engine would be a lot more customizable, prolly faster and it would be "your own" engine.
Or you could just use the DelphiX SpriteEngine and alter the code to suit your needs.

Share this post


Link to post
Share on other sites
Harry Hunt    542
I use my own DirectX wrappers (XCESS game development kit - will be published soon) and my own sprite engine.
It''s a lot faster than DelphiX, uses the well-commented Jedi-Headers and works quite well.

Share this post


Link to post
Share on other sites
DragonPhinn    122
I hate the DelphiX SpriteEngine, but only because I don''t know it. It makes things easier, once you get the hang of it. Personally, however, I would rather write my own code and use it, only because a) it''s mine, and b) I know everything about it. The only thing I want the SpriteEngine for is for collision detection, because thats a difficult topic for me.

Share this post


Link to post
Share on other sites
Harry Hunt    542
Part of my sprite engine with bounding-box collision detection.


  
TDXCustomSprite = class(TObject)
private
FY: Integer;
FTag: Integer;
FImageIndex: Integer;
FX: Integer;
FFrame: Integer;
FName: String;
FBoundingBox: TRect;
public
function TestCollision(Sprite: TDXCustomSprite): Boolean;

property X: Integer read FX write FX;
property Y: Integer read FY write FY;

property BoundingBox: TRect read FBoundingBox write FBoundingBox;
property Frame: Integer read FFrame write FFrame;
property Name: String read FName write FName;
property ImageIndex: Integer read FImageIndex write FImageIndex;
property Tag: Integer read FTag write FTag;
end;

implementation

{ TDXCustomSprite }

function TDXCustomSprite.TestCollision(Sprite: TDXCustomSprite): Boolean;
var
RX, RY: Integer;
SPRX, SPRY: Integer;

CRX, CRY: Integer;
SPCRX, SPCRY: Integer;

DeltaX, DeltaY: Integer;
begin
RX:= (Self.BoundingBox.Right - Self.BoundingBox.Left) div 2;
RY:= (Self.BoundingBox.Bottom - Self.BoundingBox.Top) div 2;

SPRX:= (Sprite.BoundingBox.Right - Sprite.BoundingBox.Left) div 2;
SPRY:= (Sprite.BoundingBox.Bottom - Sprite.BoundingBox.Top) div 2;

CRX:= Self.X + RX;
CRY:= Self.Y + RY;

SPCRX:= Sprite.X + SPRX;
SPCRY:= Sprite.Y + SPRY;

DeltaX:= Abs(SPCRX - CRX);
DeltaY:= Abs(SPCRY - CRY);

If (DeltaX < RX + SPRX) and (DeltaY < RY + SPRY) then
Result:= true
else
Result:= false;
end;


[edited by - Harry Hunt on May 10, 2002 11:56:15 AM]

Share this post


Link to post
Share on other sites