Hello all!
I'm currently programming the backbones for a top-down shooting game using SFML 2.1 and C++. I'm getting around to implementing projectiles and collision detection between projectiles and enemy units, however when I added the bounding box collision detection to my game loop it made the game drop from an even 60 FPS to a low 30 FPS.
My game-loop looks similar to this:
while(playing)
{
//input
//other processing
if(BBCollision(player.getProjectile().getSprite(), enemy.getSprite()) == true){
enemy.setDraw(false);
}
// output
}
And my function looks like this:
bool BBCollision(sf::Sprite sprite1, sf::Sprite sprite2){
if( sprite1.getPosition().x > sprite2.getPosition().x + sprite2.getGlobalBounds().width &&
sprite1.getPosition().y > sprite2.getPosition().y + sprite2.getGlobalBounds().height &&
sprite2.getPosition().x > sprite1.getPosition().x + sprite1.getGlobalBounds().width &&
sprite2.getPosition().y > sprite1.getPosition().y + sprite1.getGlobalBounds().height)
return true;
else
return false;
}
So can anyone point me what I did wrong and what I could do to get rid of the lag? Thank you in advance