2D camera that defines what region is shown on screen.
auto window = RenderWindow(); auto view = View(); // Initialize the view to a rectangle at (100, 100) and 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.view = view; // Render stuff window.draw(someSprite); // Set the default view back window.view = window.getDefaultView(); // Render stuff not affected by the view window.draw(someText);
$(PARA See also the note on coordinates and undistorted rendering in $(TRANSFORMABLE_LINK).)
$(RENDERWINDOW_LINK), $(RENDERTEXTURE_LINK)
$(U 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 has not 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, every objects drawn in this render target will be affected by the view until you use another view.