• Advertisement
Sign in to follow this  

Destroying Bullets / Enemies

This topic is 2527 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

Hi ,
Me again , using XNA 4.0 (C#).
Just wondering how id go about actually destroying bullets or enemies?.

Right now , my bullet , and enemy are 2D textures.
At the moment im kind of cheating , when the player let goes of space , the texture moves to like -5000,-5000 (off the screen)

This is obviously a bad way to do it , and if the player holds the fire button , the texture seems to stay in the last position.

If i can get a way to destroy the bullet , the enemies would be just as easy.

heres an example of what im doing for my powerup...
[code] if (powerCollision == true)
{
powerUpPos = new Vector2(-5000, -5000);



}
[/code]

Share this post


Link to post
Share on other sites
Advertisement
You can maintain a [b]bool isVisible[/b] variable, enabling it and disabling it. If disabled, don't render it. If you're rendering offscreen items and just letting them be culled because they're offscreen, you're losing performance. It would be quicker to do [b]if( isVisible ) powerUp->Render()[/b].

Share this post


Link to post
Share on other sites
In managed languages (such as C# and Java), once there are no more references to an object, it will automatically be deleted. Just remove any references to your bullet. If it is in a list, remove it from the list. If it is just a single item, set the variable to null. This does mean you will probably need to put your removal logic outside of the object itself.

Share this post


Link to post
Share on other sites
Cheers Buckeye , your idea worked perfect.
Now when i hold space my ship fires , and the image becomes unvisible right after. and repeats as long as space is held!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement