Hi everyone. My game is a SpaceFighter programmed with DelphiX. I followed Mr Farmer's advice and created a seperate class for the explosion, i.e.when my bullet hits my enemy the enemy image is replaced by an animated explosion:
Code:
//The explosion class
TExplode = class(TImageSprite)
public
constructor Create(AParent: TSprite); override;
end;
Constructor TExplode.Create(AParent: TSprite);
begin
inherited Create(AParent);
self.Image := Form1.DXImageList1.Items[form1.ExplodeImageIndex];
self.X := Enemy.X;
self.Y := Enemy.Y;
self.Width := Enemy.Image.Width;
self.Height := Enemy.Image.Height;
self.PixelCheck := False;
self.AnimCount := Image.PatternCount;
//self.AnimLooped:= True;
self.AnimSpeed:= (60/1000) * UpdateSpeed;
end;
procedure TForm1.BulletCollision(Sender:TObject;var done:Boolean);
begin
if (sender is TEnemy) then
begin
Enemy := TEnemy(sender);
if (not Enemy.Hit) then
begin
Explode := TExplode.Create(dxSpriteEngine1.Engine);
Enemy.hit := true;
Enemy.Dead;
Bullet.Dead;
Points := Points + 1000;
EnemyCount := EnemyCount + 1;
Enemy := TEnemy.create(dxspriteEngine1.Engine,dximageList1,EnemyLeftImageIndex);
end;
end
else ...
Problem is that once the bullet hits the enemy the explosion animation runs perfectly but stops at the last image of the animation. This "last" image of the animation then stays on ths screen. How do I kill it? Explode.Dead kills it but then the animation does not run :-(
Bookmarks