This isn't necessarily a SFML related question, more likely I just am having a hard time wrapping my head around the logic needed to restrict the sf::View movement.
I want the view to move with the player, however I do not want it to display past a certain set of coordinates, whatever my play field will be (0,0) to (800,2000) or whatever.
Currently I use GetPosition on a player sprite and then set the center of my view to the same position.
Then I try to check the edges of the view against coords to stop it from moving, which I am doing all wrong so far.
sf::Vector2f player_pos = PlayerSprite.GetPosition();
sf:vector2f view_center = View.GetCenter();
sfVector2f view_size = View.GetSize();
if(view_center.x - (view_size.x /2) >= 0)
{
View.SetCenter(player_pos)
}
I have also tried
if(player_pos.x - (view_size.x /2) >= 0)
{
View.SetCenter(player_pos)
}
This appears to work if I don't go too far left, when I do the view freezes, because my equation obviously will never equal or go above 0;
I guess I am looking for some advice to stop the view from moving based on player position. I know i need some combonation of Player position, view size and position. But so far my attempts have all been thwarted.
Thanks!