2D camera that defines what region is shown on screen
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.
val window: RenderWindow = ???
val view: View = ???
val someSprite: Sprite = ???
val someText: Text = ???
// Initialize the view to a rectangle located at (100, 100) and with a size of 400x200
view.reset((100, 100, 400, 200))
// Rotate it by 45 degrees
view.rotate(45)
// Set its target viewport to be half of the window
view.viewport = (0f, 0f, 0.5f, 1f)
// Apply it
window.view = view
// Render stuff
window.draw(someSprite)
// Set the default view back
window.view = window.defaultView
// Render stuff not affected by the view
window.draw(someText)
See also the note on coordinates and undistorted rendering in Transformable.
Attributes
- See also
- Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
Members list
Value members
Concrete methods
Get the inverse projection transform of the view.
Get the inverse projection transform of the view.
This function is meant for internal use only.
Attributes
- Returns
-
Inverse of the projection transform defining the view
- See also
Reset the view to the given rectangle.
Reset the view to the given rectangle.
Note that this function resets the rotation angle to 0.
Value parameters
- rectangle
-
Rectangle defining the zone to display
Attributes
- See also
Rotate the view relatively to its current orientation.
Rotate the view relatively to its current orientation.
Value parameters
- angle
-
Angle to rotate, in degrees
Attributes
- See also
Get the current orientation of the view.
Get the current orientation of the view.
Attributes
- Returns
-
Rotation angle of the view, in degrees
- See also
Set the orientation of the view.
Set the orientation of the view.
The default rotation of a view is 0 degree.
Value parameters
- angle
-
New angle, in degrees
Attributes
- See also
Get the projection transform of the view.
Get the projection transform of the view.
This function is meant for internal use only.
Attributes
- Returns
-
Projection transform defining the view
- See also
Get the target viewport rectangle of the view.
Get the target viewport rectangle of the view.
Attributes
- Returns
-
Viewport rectangle, expressed as a factor of the target size
- See also
Set the target 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.viewport = (0f, 0f, 0.5f, 1f)
. By default, a view has a viewport which covers the entire target.
Value parameters
- viewport
-
New viewport rectangle
Attributes
- See also
Resize the view rectangle relatively to its current size.
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)
Value parameters
- factor
-
Zoom factor to apply
Attributes
- See also