2D camera that defines what region is shown on screen More...
#include <View.hpp>
Public Member Functions | |
View () | |
Default constructor. More... | |
View (const FloatRect &rectangle) | |
Construct the view from a rectangle. More... | |
View (const Vector2f ¢er, const Vector2f &size) | |
Construct the view from its center and size. More... | |
void | setCenter (float x, float y) |
Set the center of the view. More... | |
void | setCenter (const Vector2f ¢er) |
Set the center of the view. More... | |
void | setSize (float width, float height) |
Set the size of the view. More... | |
void | setSize (const Vector2f &size) |
Set the size of the view. More... | |
void | setRotation (float angle) |
Set the orientation of the view. More... | |
void | setViewport (const FloatRect &viewport) |
Set the target viewport. More... | |
void | reset (const FloatRect &rectangle) |
Reset the view to the given rectangle. More... | |
const Vector2f & | getCenter () const |
Get the center of the view. More... | |
const Vector2f & | getSize () const |
Get the size of the view. More... | |
float | getRotation () const |
Get the current orientation of the view. More... | |
const FloatRect & | getViewport () const |
Get the target viewport rectangle of the view. More... | |
void | move (float offsetX, float offsetY) |
Move the view relatively to its current position. More... | |
void | move (const Vector2f &offset) |
Move the view relatively to its current position. More... | |
void | rotate (float angle) |
Rotate the view relatively to its current orientation. More... | |
void | zoom (float factor) |
Resize the view rectangle relatively to its current size. More... | |
const Transform & | getTransform () const |
Get the projection transform of the view. More... | |
const Transform & | getInverseTransform () const |
Get the inverse projection transform of the view. More... | |
Detailed Description
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 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.
Usage example:
See also the note on coordinates and undistorted rendering in sf::Transformable.
- See also
- sf::RenderWindow, sf::RenderTexture
Constructor & Destructor Documentation
sf::View::View | ( | ) |
Default constructor.
This constructor creates a default view of (0, 0, 1000, 1000)
|
explicit |
Construct the view from a rectangle.
- Parameters
-
rectangle Rectangle defining the zone to display
Construct the view from its center and size.
- Parameters
-
center Center of the zone to display size Size of zone to display
Member Function Documentation
const Vector2f& sf::View::getCenter | ( | ) | const |
const Transform& sf::View::getInverseTransform | ( | ) | const |
Get the inverse projection transform of the view.
This function is meant for internal use only.
- Returns
- Inverse of the projection transform defining the view
- See also
- getTransform
float sf::View::getRotation | ( | ) | const |
Get the current orientation of the view.
- Returns
- Rotation angle of the view, in degrees
- See also
- setRotation
const Vector2f& sf::View::getSize | ( | ) | const |
const Transform& sf::View::getTransform | ( | ) | const |
Get the projection transform of the view.
This function is meant for internal use only.
- Returns
- Projection transform defining the view
- See also
- getInverseTransform
const FloatRect& sf::View::getViewport | ( | ) | const |
Get the target viewport rectangle of the view.
- Returns
- Viewport rectangle, expressed as a factor of the target size
- See also
- setViewport
void sf::View::move | ( | float | offsetX, |
float | offsetY | ||
) |
void sf::View::move | ( | const Vector2f & | offset | ) |
void sf::View::reset | ( | const FloatRect & | rectangle | ) |
Reset the view to the given rectangle.
Note that this function resets the rotation angle to 0.
- Parameters
-
rectangle Rectangle defining the zone to display
- See also
- setCenter, setSize, setRotation
void sf::View::rotate | ( | float | angle | ) |
Rotate the view relatively to its current orientation.
- Parameters
-
angle Angle to rotate, in degrees
- See also
- setRotation, move, zoom
void sf::View::setCenter | ( | float | x, |
float | y | ||
) |
void sf::View::setCenter | ( | const Vector2f & | center | ) |
void sf::View::setRotation | ( | float | angle | ) |
Set the orientation of the view.
The default rotation of a view is 0 degree.
- Parameters
-
angle New angle, in degrees
- See also
- getRotation
void sf::View::setSize | ( | float | width, |
float | height | ||
) |
void sf::View::setSize | ( | const Vector2f & | size | ) |
void sf::View::setViewport | ( | const FloatRect & | viewport | ) |
Set the target viewport.
The viewport is the rectangle into which the contents of the view are displayed, expressed as a factor (between 0 and 1) of the size of the RenderTarget to which the view is applied. For example, a view which takes the left side of the target would be defined with View.setViewport(sf::FloatRect(0, 0, 0.5, 1)). By default, a view has a viewport which covers the entire target.
- Parameters
-
viewport New viewport rectangle
- See also
- getViewport
void sf::View::zoom | ( | float | factor | ) |
Resize the view rectangle relatively to its current size.
Resizing the view simulates a zoom, as the zone displayed on screen grows or shrinks. factor is a multiplier:
- 1 keeps the size unchanged
- > 1 makes the view bigger (objects appear smaller)
- < 1 makes the view smaller (objects appear bigger)
- Parameters
-
factor Zoom factor to apply
The documentation for this class was generated from the following file: