I want to use sf::View in SFML in order to change the position of the view, such that the player sprite is always in the center of the screen. Thus I want to write a function which allows me to input a set of coordinates and thus center the screen around those coordinates. In addition I want to be able to set a limit to this, such that when the player reaches the side of the map, that axis of the camera stops following the player, as it has reached a "limit". How do I achieve this?
You have to check if the player is too close to a side and move the view accordingly.
If he is too much on one side then you don't center the view on him anymore.
Here is an example of how I would do it. (I haven't tested it)
//View is your current view.
//Position is the position you want to center the view on.
//Size is the size of your "area".
void move_view(View &view, sf::Vector2f size ,sf::Vector2f position)
if (position.x > size.x-view.getSize().x/2)//on the right side
position.x = size.x-view.getSize().x/2;
if (position.x < view.getSize().x/2)//on the left side
position.x = view.getSize().x/2;
//same for up and down