PDA

View Full Version : Creating some sort of sprite engine ...



hammer
04-07-2004, 10:21 AM
Okay so i've reached a point where i need to create objects but dunno how many they will be i.e. a ship firing, placing a new building etc.
I know that in delphix there was a spriteengine that handles this stuff but in d3d how do i handle such kind of stuff ?
What do i need to do ?
cous i dont want to create arrays all the time .....

Paulius
04-07-2004, 10:59 AM
You could check out DelphiX's source to see how it's done. You'll still need an array or some better container like a linked list to store your objects, but your object engine should automate things like storing objects in that container, calling some virtual method of all objects (they should be derived from your base object class) etc.

TheLion
04-07-2004, 12:23 PM
I think DelphiX uses typecasting, all the sprites of the spriteengine where derived from TDXSprite (or something like that), so all of the components will have all of their parents methods and properties (except the overridden once). It probably also uses a container of some sort to keep track of the components, so you could typecast like:

Type TMyCustomSprite = class(TDXSprite);
...
End;

SpriteObj : TMyCustomSprite;

inside your sprite engine:
TDXSprite(SpriteObj).Move(X, Y);

That way you wouldn't have to know what type of object has been created, but only that it's been derived from your sprite component and you know which functions that component has! :)

Basically you can convert an object to another type of object and talk to the other objects functions, however this only works with objects that objects higher in the hierarchy have been derived... For example all objects are derived from TObject so you can typecast any object or component to TObject by saying: TObject(MyComponent)

(It could be that this doesn't make a lot of sense... kinda hard to explain this, however I think the Delphi help file talks about it somewhere) :)

hammer
04-07-2004, 04:25 PM
hm.... probably i can use the basics of the DelphiX spriteengine to create spriteengine for a d3d enviroment ?
thanks for the replies