Hmmm, perhaps comments might help more. Same code commented:
// SFMLTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
int main(int argc, char ** argv)
{
sf::RenderWindow window; // Declare a window object
window.Create(sf::VideoMode(1024,768,32),"Test"); // Create the window, setting the resolution and pixel depth
sf::Image img; // Declare an image object
if(!img.LoadFromFile("ship.png")) return 42; // Load our image from file, if it fails, exit the program
sf::Sprite sprite(img); // Declare a sprite, and in it's constructor assign an image to it. There can be multiple sprites to a single image
sprite.SetX(( 1024/2 - img.GetWidth() /2)); // Position the sprite in the middle of the screen
sprite.SetY((768/2 - img.GetHeight() /2));
//Gameloop
bool done = false; // Boolean variable flag that will tell us when to exit the program
while(!done) // Loop ( "game loop" ) forever, or until the "done" flag is set to true
{
sf::Event myEvent; // declare an event
while(window.GetEvent(myEvent)) // GetEvent returns true if there is a new event, if there is an event, handle it, otherwise proceed to drawing
{
switch(myEvent.Type) // Switch ( think a branching if statement ) on the type of event we are processing
{
case sf::Event::Closed: // If the event is a close type, set the done flag to true so we exit next pass through the loop
done = true;
break; // You need a break statement for every case: condition, or the switch will "fall through" and continue processing
case sf::Event::KeyPressed: // Is it a key press event?
{
switch(myEvent.Key.Code) // If so, which Key?
{
case sf::Key::W: // Handle the various keys
{
sprite.Move(0,-1); // Move up 1 pixel
break;
}
case sf::Key::A:
{
sprite.Move(-1,0); // Move left
break;
}
case sf::Key::S:
{
sprite.Move(0,1); // Move down
break;
}
case sf::Key::D:
{
sprite.Move(1,0); // Move right
break;
}
case sf::Key::Q:
{
sprite.Rotate(-1.f); // Rotate 1 degree left
break;
}
case sf::Key::E:
{
sprite.Rotate(1.f); // Rotate 1 degree right
break;
}
}
break;
}
}
}
// done handling events
window.Clear(sf::Color::White); // Clear the screen to white
window.Draw(sprite); // Draw your sprite to the screen
window.Display(); // Display the screen
}// Now we are done "one" pass through the game loop, continue to next pass getting input, drawing screen, etc... until done is true
window.Close(); // Close the window
return 0; // Return "everythingAOK code
}