Class OcsfmlGraphics.view

class view : [ `Center of (float * float) * (float * float)
| `Copy of < rep__sf_View : View.t; .. >
| `None
| `Rect of FloatRect.t ] ->
object .. end
2D camera that defines what region is shown on screen.

OcsfmlGraphics.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:

    let window = new render_window (* ... *) in
    let view = new view `None in
    
    (* Initialize the view to a rectangle located 
       at (100, 100) and with a size of 400x200 *)

    view#reset { left = 100.; top = 100.; width = 400.; height = 200. } ;
    
    (* Rotate it by 45 degrees *)
    view#rotate 45. ;
    
    (* Set its target viewport to be half of the window *)
    view#set_viewport { left = 0.; top = 0.; width = 0.5; height =  1. } ;
    
    (* Apply it *)
    window#set_view view ;
    
    (* Render stuff *)
    window#draw someSprite ;
    
    (* Set the default view back *)
    window#set_view window#get_default_view ;
    
    (* Render stuff not affected by the view *)
    window#draw someText 
    


method destroy : unit
method affect : 'a. (#const_view as 'a) -> unit
method get_center : float * float
Get the center of the view.
Returns Center of the view.
method get_rotation : float
Get the current orientation of the view.
Returns Rotation angle of the view, in degrees.
method get_size : float * float
Get the size of the view.
Returns Size of the view.
method get_viewport : FloatRect.t
Get the target viewport rectangle of the view.
Returns Viewport rectangle, expressed as a factor of the target size.
method move : float -> float -> unit
Move the view relatively to its current position.
method move_v : float * float -> unit
Move the view relatively to its current position.
method reset : FloatRect.t -> unit
Reset the view to the given rectangle.

Note that this function resets the rotation angle to 0.

method rotate : float -> unit
Rotate the view relatively to its current orientation.
method set_center : float -> float -> unit
Set the center of the view.
method set_center_v : float * float -> unit
Set the center of the view.
method set_rotation : float -> unit
Set the orientation of the view.

The default rotation of a view is 0 degree.

method set_size : float -> float -> unit
Set the size of the view.
method set_size_v : float * float -> unit
Set the size of the view.
method set_viewport : FloatRect.t -> unit
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 OcsfmlGraphics.render_target 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.

method zoom : float -> unit
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: