So here's what I came up with. Notice that we're not moving the sprite around, we're moving the view (camera) around. The other thing is that I think (hope) that this is the wrong way to move the view around, setting it every time, but it's the only way I could find.
#include <SFML/Graphics.hpp>
int main()
{
// Set up the window
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "SFML Sample Application");
// Load resources
sf::Image ourImage;
ourImage.Create(64, 64, sf::Color(85, 85, 85));
sf::Texture ourTexture;
ourTexture.Create(64, 64); // Give our texture a width (in pixels)
ourTexture.LoadFromImage(ourImage);
sf::Sprite ourSprite;
ourSprite.SetTexture(ourTexture);
ourSprite.SetPosition(0, 0);
ourSprite.SetScale(5, 5);
// Create our own view (none of that sissy default stuff)
sf::View ourView;
ourView.Reset(sf::FloatRect(100, 100, 400, 200));
ourView.SetViewport(sf::FloatRect(0.f, 0.f, 1.f, 1.f));
Window.SetView(ourView);
// Main loop
while (Window.IsOpen())
{
// Handle Events
sf::Event e;
while (Window.PollEvent(e))
{
// Lets handle the events
switch (e.Type)
{
case sf::Event::Closed:
Window.Close();
break;
case sf::Event::KeyPressed:
// Handle Keyboard input
if(e.Key.Code == sf::Keyboard::W)
ourView.Move(0.f, -10.f); // Move up
else if(e.Key.Code == sf::Keyboard::A)
ourView.Move(-10.f, 0.f); // Move left
else if(e.Key.Code == sf::Keyboard::S)
ourView.Move(0.f, 10.f);// Move down
else if(e.Key.Code == sf::Keyboard::D)
ourView.Move(10.f, 0.f);// Move right
break;
default:
break;
}
}
// Clear the old stuff
Window.Clear(sf::Color(0, 255, 255));
// Re-draw our sprite
Window.Draw(ourSprite);
// Display the window (swap buffers?)
Window.SetView(ourView);
Window.Display();
}
return 0;
}