Archived

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

Destroying Sprites

This topic is 5710 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everybody! I''m new to DelphiX programming but I''m making really good progresses. What I need to do is destroy many sprites at one time. My situation: I have 60 sprites from the class TEnemy in the screen. When the player dies, If the user starts a new game the game will add more 60 players and the previouse 60 (or less, if the player killed someone) will need to be destroyed. I don''t know How to Use the Destroy, Free, or Dead to destroy too many sprites so...I would like some help here! Thanks in advanced, Marcelo.

Share this post


Link to post
Share on other sites
This is only for DelphiX

//Do for all sprites in current engine
for I := 0 to Engine.AllCount - 1 do

//Here You check sprite for dead
if Engine.Items is TDeadSprite
then Engine.Items[I].Dead;

Engine.Dead; //Do dead and destroy operation

I try code

Engine.Items[I].Free;

but then counter is changed and not destroying all sprites.

Share this post


Link to post
Share on other sites
This code would free all the sprites (including the player):

while Engine.Count > 0 do
  Engine.Items[Engine.Count - 1].Free;


or this code would kill all TEnemy sprites:

for j := 0 to Engine.Count - 1 do begin
  if Engine.Items[j] is TEnemy then Engine.Items[j].Dead;
end;
Engine.Dead;


Possibly you should have some kind of recursive function in case there are any sprites owned by other sprites.

[edited by - Useless Hacker on May 30, 2002 8:08:30 AM]

Share this post


Link to post
Share on other sites