Hiya,

To come back to earlier questions of mine where I was asking how to manage sprites and especially their textures (in 2D game) everybody recommended some sort of sprite manager class which takes care of creating and releasing the sprites.

So, if I have a class called TSprite which is a ultimate ancestor for all objects on the game and then I have TSpriteManager class which creates sprites and manages them every way.

How that sprite manager "SpriteCreate" and "SpriteDestroy" functions should be implemented, so that they are compatible with inherited objects also?

I mean. If I create a ingame object called TShuttle for example which is inherited from TSprite class. How the sprite managers "CreateSprite" function knows which type of object should be initialized now?

If those functions returns created TSprite class, then those aren't compatible with TShuttle class (which in fact is a sprite with additional methods)?

some code to explain what I mean

Code:
TSprite = Class
private
    Texture: IDirect3DTexture9;
     FileName: String;
public
    constructor Create;
    destructor   Destroy; override;
end;


TShuttle = Class(TSprite)
private
    FRotationAngle: Single;
public
    property Rotation: Single read FRotationAngle write FRotationAngle;
    procedure Rotate(Angle: single);
end;

TSpriteManager = Class(Tlist)
private
public
   function CreateSprite(Filename: String): TSprite;
   function DeleteSprite(Filename: String): Boolean;
end;

function TSpriteManager.CreateSprite(Filename: String): TSprite;
begin
    // Pseudo code here.
    Search(FileName) from sprite manager.

    if sprite is already stored then
        create sprite and set it's texture to point already loaded texture.
    else
        create sprite, load texture and store sprite to manager.
    
    result := created sprite;
end;
So, in above "code" there. In the abstract way. What I have to change so I can create TShuttle structure also with manager and store that into it?


edit: Hmm...I keep asking questions and soon after that I solve the problem by myself . I think I should begin to think little before I ask. :?

So, the problem is solved. I made a class which loads textures and holds pointers to them. Then I made a class which stores a list of pointers to those classes which holds the pointers to the textures (animated textures). And manages them every way.

Then I made Sprite class which gets that manager class as an parameter when creating itself. Sprites create method checks if texture(s) for this sprite is allready loaded or not in manager. If not then it tells manager to load it and store to memory.

From that sprite class I can inherit as many object I want and all textures are shared by the manager.