Can putting “if” statements inside a loop actually lowers the number of computations and speed up the program, or does it instead makes the program slower since now the program is going through one more step of checking?
Will this collision checking code be slower :-
void Player::checkCollision(vector<sf::FloatRect> blocks)
{
//checking if player is on top of a block
for(unsigned int i=0; i<blocks.size(); i++)
{
sf::FloatRect r = blocks[i];
if(r.contains(point[9]) || r.contains(point[10]) || r.contains(point[11]))
{
colDown = true;
break;
}
colDown = false;
}
}
then this collision checking code? :-
void Player::checkCollision(vector<sf::FloatRect> blocks)
{
//checking if player is on top of a block
for(unsigned int i=0; i<blocks.size(); i++)
{
if(blocks[i].getX()>0 && blocks[i].getX()<screenWidth)
{
sf::FloatRect r = blocks[i];
if(r.contains(point[9]) || r.contains(point[10]) || r.contains(point[11]))
{
colDown = true;
break;
}
colDown = false;
}
}
}