2D camera that defines what region is shown on screen
sf.View defines a camera in the 2D scene.
This is a very powerful concept: you can scroll, rotate or zoom the entire scene without altering the way that your drawable objects are drawn.
A view is composed of a source rectangle, which defines what part of the 2D scene is shown, and a target viewport, which defines where the contents of the source rectangle will be displayed on the render target (window or texture).
The viewport allows to map the scene to a custom part of the render target, and can be used for split-screen or for displaying a minimap, for example. If the source rectangle doesn't have the same size as the viewport, its contents will be stretched to fit in.
To apply a view, you have to assign it to the render target. Then, objects drawn in this render target will be affected by the view until you use another view.
now the same view but is rotate
using a viewport, it is straightforward to split the screen for multiplayer games:
// player 1 (left side of the screen)
player1View.setViewport(FloatRect(0.f, 0.f, 0.5f, 1.f));
// player 2 (right side of the screen)
player2View.setViewport(FloatRect(0.5f, 0.f, 0.5f, 1.f));
view can create a mini-map
// the game view (full window)
gameView.setViewport(FloatRect(0.f, 0.f, 1.f, 1.f));
// mini-map (upper-right corner)
minimapView.setViewport(FloatRect(0.75f, 0.f, 0.25f, 0.25f));
Usage example:
var window = new RenderWindow({500, 500}, "title");
var view = new View();
// Initialize the view to a rectangle located at (100, 100) and with a size of 400x200
view.reset(FloatRect(100, 100, 400, 200));
// Rotate it by 45 degrees
view.rotate(45);
// Set its target viewport to be half of the window
view.setViewport(FloatRect(0.f, 0.f, 0.5f, 1.f));
// Apply it
window.setView(view);
// Render stuff
window.draw(someSprite);
// Set the default view back
window.setView(window.getDefaultView());
// Render stuff not affected by the view
window.draw(someText);
See also the note on coordinates and undistorted rendering in sf.Transformable.