SFML community forums

Help => General => Topic started by: Aquacalvin on February 28, 2014, 07:04:04 pm

Title: How to "Kill" Things
Post by: Aquacalvin on February 28, 2014, 07:04:04 pm
Hey everyone! I am a noob SFML coder. I have only made games like pong etc. with SFML. I am now ready to move on to greater things. I have a question though. Is there a simple way to make a game entity disappear once it has been touched, blown up, etc. Also, I need it the be unseen and to be "solid" in the game (so stuff can't hit it). Thanks!
Calvin
Title: Re: How to "Kill" Things
Post by: Jesper Juhl on February 28, 2014, 07:09:14 pm
If you don't want it on the screen anymore, simply stop drawing it.
If you don't want "stuff" to hit it, stop making collision tests against "it" and "stuff" once it is "killed".
Title: Re: How to "Kill" Things
Post by: Aquacalvin on February 28, 2014, 07:43:30 pm
thanks!
Title: Re: How to "Kill" Things
Post by: Nexus on February 28, 2014, 08:13:15 pm
If you want something to not exist anymore, remove it from the data structure that contains it.

For example, this code removes all elements, for which the isDead member function returns true, from the container.
std::vector<Entity> entities;
...
auto newEnd = std::remove_if(entities.begin(), entities.end(), std::mem_fn(&Entity::isDead));
entities.erase(newEnd, entities.end());