Hi Guys, I'm having trouble trying to know if a sprite is inside the current view, this is my code:
bool Sector::lightInView(sf::FloatRect spriteAABB)
{
sf::Vector2i viewCenter(Game::GetWindow()->getView().getCenter()); // global coords, right?
sf::Vector2i viewSize(Game::GetWindow()->getView().getSize()); // in this case: 1680x1050
// create the view Rect, are the -/+ ok?
sf::FloatRect currentViewRect
(viewCenter.x - viewSize.x / 2,
viewCenter.y + viewSize.y / 2,
viewCenter.x + viewSize.x / 2,
viewCenter.y - viewSize.y / 2);
// check if the sprite is in view
return (spriteAABB.intersects(currentViewRect));
}
This isn't working, I know because the sprites are lights that I only draw when they are in view. They won't draw or draw when not in view, etc.
I'm having trouble understanding the coordinates system, it's probably an issue with that.