I have added the Animated Base Sprite class that now allows sprites to be created with built in functionality for handling animation. I have also created a new batch class that holds two lists of item. This batch allows me to create a "pool" of sprites held in what I call the "Dead List". A simple call to the batch transfers a "Dead" sprite to the "Live List". Any sprite on the Live List will be rendered. Once a sprite on the Live List is no longer needed another call will transfer it back to the Dead List ready for reuse. I am using some custom written Double Linked Lists to achieve this functionality. This will have speed gains over the built in Delphi TList class. The code below shows how I add three sprites to the SpritePool's Dead List. A single call to "Pool.Acquire" will move a sprite from the Dead List and place it on the Live List. The SpritePool Live List is then passed to the Graphics Device where the sprite is rendered. The SpritePool will be used where large volumes of sprites may need to be used in a hurry. A good example could be an explosion made up of many sprites. By creating a pool before the game play starts, there won't be an slow down when multiple explosions are required. Additional code could be added so that if the Pool ran out of "Dead" sprites, new ones could be created on-the-fly. Obviously we don't want this to happen so some careful calculations should be performed to optimise the size of the Pool.
Any comments ?
procedure TForm1.btnListTestClick (Sender : TObject) ;
GraphicDev : TGraphicsDevice ;
Content : TVisualContent ;
Pool : TSpritePool ;
GraphicDev := TGraphicsDevice.Create (800, 600, bs24) ;
Content := TVisualContent.Create ('Images') ;
Pool := TSpritePool.Create ;
Pool.AddToDeadList (TTestSprite.Create (Content.GetImage ('Pic1'), 90, 90, 2)) ;
Pool.AddToDeadList (TTestSprite.Create (Content.GetImage ('Pic2'), 100, 100, 5)) ;
Pool.AddToDeadList (TTestSprite.Create (Content.GetImage ('Pic3'), 110, 110, 3)) ;
GraphicDev.DrawSpritePool (Pool.LiveList) ;