View

sfml.graphics.View
See theView companion object
trait View(using ctor: ctor)

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.

The scissor rectangle allows for specifying regions of the render target to which modifications can be made by draw and clear operations. Only pixels that are within the region will be able to be modified. Pixels outside of the region will not be modified by draw or clear operations.

Certain effects can be created by either using the viewport or scissor rectangle. While the results appear identical, there can be times where one method should be preferred over the other. Viewport transformations are applied during the vertex processing stage of the graphics pipeline, before the primitives are rasterized into fragments for fragment processing. Since viewport processing has to be performed and cannot be disabled, effects that are performed using the viewport transform are basically free performance-wise. Scissor testing is performed in the per-sample processing stage of the graphics pipeline, after fragment processing has been performed. Because per-sample processing is performed at the last stage of the pipeline, fragments that are discarded at this stage will cause the highest waste of GPU resources compared to any method that would have discarded vertices or fragments earlier in the pipeline. There are situations in which scissor testing has to be used to control whether fragments are discarded or not. An example of such a situation is when performing the viewport transform on vertices is necessary but a subset of the generated fragments should not have an effect on the stencil buffer or blend with the color buffer.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def center: Immutable[Vector2[Float]]

Get the center of the view.

Get the center of the view.

Attributes

Returns

Center of the view

See also
def center_=(center: Immutable[Vector2[Float]]): Unit

Set the center of the view.

Set the center of the view.

Value parameters

center

New center

Attributes

See also

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
def move(offset: Immutable[Vector2[Float]]): Unit

Move the view relative to its current position.

Move the view relative to its current position.

Value parameters

offset

Move offset

Attributes

See also
def rotate(angle: Immutable[Angle]): Unit

Rotate the view relative to its current orientation.

Rotate the view relative to its current orientation.

Value parameters

angle

Angle to rotate

Attributes

See also

Get the current orientation of the view.

Get the current orientation of the view.

Attributes

Returns

Rotation angle of the view

See also
def rotation_=(angle: Immutable[Angle]): Unit

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

Attributes

See also
def scissor: Immutable[Rect[Float]]

Get the scissor rectangle of the view.

Get the scissor rectangle of the view.

Attributes

Returns

Scissor rectangle, expressed as a factor of the target size

See also
def scissor_=(scissor: Immutable[Rect[Float]]): Unit

Set the target scissor viewport.

Set the target scissor viewport.

The scissor rectangle, expressed as a factor (between 0 and 1) of the RenderTarget, specifies the region of the RenderTarget whose pixels are able to be modified by draw or clear operations. Any pixels which lie outside of the scissor rectangle will not be modified by draw or clear operations. For example, a scissor rectangle which only allows modifications to the right side of the target would be defined with view.scissor = ((0.5f, 0f), (0.5f, 1f)). By default, a view has a scissor rectangle which allows modifications to the entire target. This is equivalent to disabling the scissor test entirely. Passing the default scissor rectangle to this function will also disable scissor testing.

Value parameters

scissor

New scissor rectangle

Attributes

See also
def size: Immutable[Vector2[Float]]

Get the size of the view.

Get the size of the view.

Attributes

Returns

Size of the view

See also
def size_=(size: Immutable[Vector2[Float]]): Unit

Set the size of the view.

Set the size of the view.

Value parameters

size

New size

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
def viewport: Immutable[Rect[Float]]

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
def viewport_=(viewport: Immutable[Rect[Float]]): Unit

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
def zoom(factor: Float): Unit

Resize the view rectangle relative to its current size.

Resize the view rectangle relative 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