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

Author Topic: sprite is outside of window  (Read 2532 times)

0 Members and 1 Guest are viewing this topic.

DiscoNic1P

  • Newbie
  • *
  • Posts: 3
    • View Profile
sprite is outside of window
« 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))

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sprite is outside of window
« Reply #1 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))
{
    // ...
}
 
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/