1
General / Trouble using iterator for collision
« on: April 12, 2016, 11:22:35 am »
Hi,
I am having some troubles with the collision detection within SFML I have a Vector of skeletons
std::vector<Skeleton> *skeletons = new std::vector<Skeleton>();
I am then trying to test whether or not the main character intersects with the any of the enemies I am trying to do this using a iterator.
for (std::vector<Skeleton>::iterator it = skeletons->begin(); it != skeletons->end(); ++it)
{
if (mainCharacter->mSprite.getGlobalBounds().intersects(it->mSprite.getGlobalBounds()))
{
/*skeletons->erase(skeletons->begin() + *it);*/
skeletons->erase(*it);
}
}
Do you have any idea what I am doing wrong here?
Kind Regards
I am having some troubles with the collision detection within SFML I have a Vector of skeletons
std::vector<Skeleton> *skeletons = new std::vector<Skeleton>();
I am then trying to test whether or not the main character intersects with the any of the enemies I am trying to do this using a iterator.
for (std::vector<Skeleton>::iterator it = skeletons->begin(); it != skeletons->end(); ++it)
{
if (mainCharacter->mSprite.getGlobalBounds().intersects(it->mSprite.getGlobalBounds()))
{
/*skeletons->erase(skeletons->begin() + *it);*/
skeletons->erase(*it);
}
}
Do you have any idea what I am doing wrong here?
Kind Regards