So, I tried to use view to have it to follow player:
void Player::Step() {
/*if (CollisionPoint(viewXview+Mouse.getPosition(window).x,viewYview+Mouse.getPosition(window).y,ObjMan.GetObject(id))) {
sprite.setColor(sf::Color(sf::Color::Red));
} else sprite.setColor(sf::Color(sf::Color::White));*/
if (Keyboard.isKeyPressed(sf::Keyboard::Key::Right)) {
speed=2;
animXdir=1;
};
if (Keyboard.isKeyPressed(sf::Keyboard::Key::Left)) {
speed=-2;
animXdir=-1;
};
if (!Keyboard.isKeyPressed(sf::Keyboard::Key::Right) &&
!Keyboard.isKeyPressed(sf::Keyboard::Key::Left)) {
speed=0;
};
x+=speed;
viewXview=x;
viewYview=y;
view.setCenter(viewXview,viewYview);
viewXview-=320;
viewYview-=240;
Update();
};
And after a while I noticed that it is slitly shifted to the side when player is moving. And it was fixed only after I made it to call setView every tick (in main cycle, before all rendering). Is there a reason for that or am I just being dumb?