1
General / How to detect collision when RenderWindow has an sf::View?
« on: August 12, 2020, 10:16:06 pm »
Hello. I'm working on a game that uses sf::View to let the user pan and scroll around the map. However, despite lots of work, I can't find a way to have any type of collision detection (either FloatRect methods or simple math) work with sf::View.
Let's say I start with a rectangle in the center of the window, and pan such that it's now at the bottom right corner. Using .getGlobalBounds().intersects... doesn't register anything when I click the rectangle in the bottom right — only when I click where the rectangle started. Using math (mouse.x > rect.getPosition().x) doesn't work either; I don't think any aspect of a RectangleShape changes when it moves on the window due to an sf::View.
So, is there any way for me to factor a View into the calculations when I want to do collision detection?
(Any help would be appreciated!)
Let's say I start with a rectangle in the center of the window, and pan such that it's now at the bottom right corner. Using .getGlobalBounds().intersects... doesn't register anything when I click the rectangle in the bottom right — only when I click where the rectangle started. Using math (mouse.x > rect.getPosition().x) doesn't work either; I don't think any aspect of a RectangleShape changes when it moves on the window due to an sf::View.
So, is there any way for me to factor a View into the calculations when I want to do collision detection?
(Any help would be appreciated!)