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

Author Topic: After Collision, Sprite Delete!  (Read 4051 times)

0 Members and 1 Guest are viewing this topic.

Grownup

  • Newbie
  • *
  • Posts: 2
    • View Profile
After Collision, Sprite Delete!
« on: October 29, 2009, 11:00:47 am »
Hello,
   
I have a question about Collison.
And while I wish that when two objects
do with each other, a collision of
Sprite 2 is deleted. So from the screen
disappears. Only I do not know how to
which implements in the syntax.

Thanks in advance!
And excuse me for my bad
English!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
After Collision, Sprite Delete!
« Reply #1 on: October 29, 2009, 06:48:38 pm »
Hi,

There are several approaches to your problem. If you only have two sprites, you can just stop drawing one of them (don't call sf::RenderWindow::Draw()).

But to be flexible and use more than two objects, you can use STL-containers. You store your objects in a container and check each of it for collision with others. If two objects collide, you will delete one of them (according to your logic).
Code: [Select]
std::vector<sf::Sprite> MySprites;
... // fill container here

// get iterator to the element you want to delete
std::vector<sf::Sprite>::iterator Itr = ...;
MySprites.erase(Itr);

If you aren't used to the Standard Template Library (STL), you could search some tutorials on google or have a look at http://www.cplusplus.com. Note that the STL is a really important part of the C++ standard library. It's very advisable to know it well when you want to work efficiently with SFML (this applies to many parts of C++).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything