Skip to main content
gamedev.net
🔒 Locked

Destroying Sprites

Started by FooFighter 2 replies 400+ views
Original Post
FooFighter
FooFighter
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.
Delphi just rules!!!
ra001
ra001
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.
Useless Hacker
Useless Hacker
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]
FooFighter
FooFighter
Thank you for the answers!!!
Delphi just rules!!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.