Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to "Kill" Things  (Read 2244 times)

0 Members and 1 Guest are viewing this topic.

Aquacalvin

  • Newbie
  • *
  • Posts: 21
    • View Profile
How to "Kill" Things
« 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

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: How to "Kill" Things
« Reply #1 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".
« Last Edit: February 28, 2014, 07:10:51 pm by Jesper Juhl »

Aquacalvin

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: How to "Kill" Things
« Reply #2 on: February 28, 2014, 07:43:30 pm »
thanks!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to "Kill" Things
« Reply #3 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());
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything