I've written a little demonstration with a bunch of graphic objects, using a view always centered on the player, so the player is always centered on the screen when he's moving.
I believe this is what you're trying to achieve, and as you can see this is quite easy to do:
1. move the player
2. set the view center as the player position
#include <SFML/Graphics.hpp>
#include <list>
void populate(std::list<sf::RectangleShape>& objects, float x, float y)
{
sf::RectangleShape s(sf::Vector2f(20, 20));
s.setPosition(x, y);
s.setFillColor(sf::Color::Green);
objects.push_back(s);
}
int main()
{
sf::RenderWindow app(sf::VideoMode(480, 320), "view demo");
// create player, at the screen center
sf::RectangleShape player(sf::Vector2f(20, 20));
player.setFillColor(sf::Color::Red);
player.setOrigin(10, 10);
player.setPosition(240, 160);
const float player_speed = 100;
// create a bunch of objects
std::list<sf::RectangleShape> objects;
populate(objects, 310, 50);
populate(objects, 100, 200);
populate(objects, 250, 160);
populate(objects, 10, 280);
populate(objects, 70, 30);
populate(objects, 120, 50);
// we create our custom view
sf::View player_view(sf::FloatRect(0, 0, app.getSize().x, app.getSize().y));
sf::Clock clock;
bool running = true;
sf::Event event;
while (running)
{
while (app.pollEvent(event))
{
if (event.type == sf::Event::Closed)
running = false;
}
// moving player
float frametime = clock.getElapsedTime().asSeconds();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
player.move(0, -player_speed * frametime);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
player.move(0, player_speed * frametime);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
player.move(-player_speed * frametime, 0);
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
player.move(player_speed * frametime, 0);
clock.restart();
// we keep our view centered on the player
player_view.setCenter(player.getPosition());
app.setView(player_view);
// rendering entities
app.draw(player);
for (std::list<sf::RectangleShape>::const_iterator it = objects.begin(); it != objects.end(); ++it)
{
app.draw(*it);
}
app.display();
app.clear();
}
app.close();
return 0;
}
I hope everything is clear.