SFML community forums

Help => Window => Topic started by: DiscoNic1P on March 07, 2022, 09:10:22 pm

Title: sprite is outside of window
Post by: DiscoNic1P on March 07, 2022, 09:10:22 pm
I just want to know how can you know when a sprite is outside a view when it is shotted by a character. Also the character can go to the border, so the mainview center.x can be the world min x and the same thing goes to the center y

if ((normalBullets.getPosition().x < player.getPosition().x - mainView.getCenter().x  || normalBullets.getPosition().x > player.getPosition().x + mainView.getCenter().x  || normalBullets.getPosition().y < player.getPosition().y - mainView.getCenter().y || normalBullets.getPosition().y > player.getPosition().y + mainView.getCenter().y))
Title: Re: sprite is outside of window
Post by: eXpl0it3r on March 08, 2022, 12:45:00 pm
Do you modify the view or viewport in anyway?
If the view is mapped 1:1 to the window, you best calculate the bounds of the view and then you can simply call .contains or .intersects instead of big boolean statements.

auto rect = sf::FloatRect{ view.getCenter() - (view.getSize() / 2.f), view.getSize() };
if (rect.contains(point))
{
    // ...
}