Viewport

Inherits: Node < Object

Category: Core

Brief Description

Creates a sub-view into the screen.

Member Functions

World find_world ( ) const
World2D find_world_2d ( ) const
Camera get_camera ( ) const
Transform2D get_canvas_transform ( ) const
Transform2D get_final_transform ( ) const
Transform2D get_global_canvas_transform ( ) const
Vector2 get_mouse_position ( ) const
int get_render_info ( int info )
Vector2 get_size_override ( ) const
ViewportTexture get_texture ( ) const
RID get_viewport_rid ( ) const
Rect2 get_visible_rect ( ) const
World2D get_world_2d ( ) const
Variant gui_get_drag_data ( ) const
bool gui_has_modal_stack ( ) const
void input ( InputEvent local_event )
bool is_size_override_enabled ( ) const
bool is_size_override_stretch_enabled ( ) const
void set_attach_to_screen_rect ( Rect2 rect )
void set_canvas_transform ( Transform2D xform )
void set_global_canvas_transform ( Transform2D xform )
void set_size_override ( bool enable, Vector2 size=Vector2( -1, -1 ), Vector2 margin=Vector2( 0, 0 ) )
void set_size_override_stretch ( bool enabled )
void set_world_2d ( World2D world_2d )
void unhandled_input ( InputEvent local_event )
void update_worlds ( )
void warp_mouse ( Vector2 to_position )

Signals

  • size_changed ( )

Emitted when the size of the viewport is changed, whether by set_size_override, resize of window, or some other means.

Member Variables

  • bool arvr
  • bool audio_listener_enable_2d
  • bool audio_listener_enable_3d
  • int debug_draw
  • bool disable_3d
  • bool gui_disable_input
  • bool gui_snap_controls_to_pixels
  • bool hdr
  • int msaa
  • bool own_world
  • bool physics_object_picking
  • int render_target_clear_mode
  • int render_target_update_mode
  • bool render_target_v_flip
  • int shadow_atlas_quad_0
  • int shadow_atlas_quad_1
  • int shadow_atlas_quad_2
  • int shadow_atlas_quad_3
  • int shadow_atlas_size
  • Vector2 size
  • bool transparent_bg
  • int usage
  • World world

Numeric Constants

  • UPDATE_DISABLED = 0 — Do not update the render target.
  • UPDATE_ONCE = 1 — Update the render target once, then switch to UPDATE_DISABLED
  • UPDATE_WHEN_VISIBLE = 2 — Update the render target only when it is visible. This is the default value.
  • UPDATE_ALWAYS = 3
  • SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED = 0
  • SHADOW_ATLAS_QUADRANT_SUBDIV_1 = 1
  • SHADOW_ATLAS_QUADRANT_SUBDIV_4 = 2
  • SHADOW_ATLAS_QUADRANT_SUBDIV_16 = 3
  • SHADOW_ATLAS_QUADRANT_SUBDIV_64 = 4
  • SHADOW_ATLAS_QUADRANT_SUBDIV_256 = 5
  • SHADOW_ATLAS_QUADRANT_SUBDIV_1024 = 6
  • SHADOW_ATLAS_QUADRANT_SUBDIV_MAX = 7
  • RENDER_INFO_OBJECTS_IN_FRAME = 0
  • RENDER_INFO_VERTICES_IN_FRAME = 1
  • RENDER_INFO_MATERIAL_CHANGES_IN_FRAME = 2
  • RENDER_INFO_SHADER_CHANGES_IN_FRAME = 3
  • RENDER_INFO_SURFACE_CHANGES_IN_FRAME = 4
  • RENDER_INFO_DRAW_CALLS_IN_FRAME = 5
  • RENDER_INFO_MAX = 6
  • DEBUG_DRAW_DISABLED = 0
  • DEBUG_DRAW_UNSHADED = 1
  • DEBUG_DRAW_OVERDRAW = 2
  • DEBUG_DRAW_WIREFRAME = 3
  • MSAA_DISABLED = 0
  • MSAA_2X = 1
  • MSAA_4X = 2
  • MSAA_8X = 3
  • MSAA_16X = 4
  • USAGE_2D = 0
  • USAGE_2D_NO_SAMPLING = 1
  • USAGE_3D = 2
  • USAGE_3D_NO_EFFECTS = 3
  • CLEAR_MODE_ALWAYS = 0
  • CLEAR_MODE_NEVER = 1
  • CLEAR_MODE_ONLY_NEXT_FRAME = 2

Description

A Viewport creates a different view into the screen, or a sub-view inside another viewport. Children 2D Nodes will display on it, and children Camera 3D nodes will render on it too.

Optionally, a viewport can have its own 2D or 3D world, so they don’t share what they draw with other viewports.

If a viewport is a child of a Control, it will automatically take up its same rect and position, otherwise they must be set manually.

Viewports can also choose to be audio listeners, so they generate positional audio depending on a 2D or 3D camera child of it.

Also, viewports can be assigned to different screens in case the devices have multiple screens.

Finally, viewports can also behave as render targets, in which case they will not be visible unless the associated texture is used to draw.

Member Function Description

  • World find_world ( ) const

Return the 3D world of the viewport, or if no such present, the one of the parent viewport.

Return the 2D world of the viewport.

Return the active 3D camera.

Get the canvas transform of the viewport.

Get the total transform of the viewport.

Get the global canvas transform of the viewport.

  • Vector2 get_mouse_position ( ) const

Get the mouse position, relative to the viewport.

  • int get_render_info ( int info )
  • Vector2 get_size_override ( ) const

Get the size override set with set_size_override.

Get the viewport’s texture, for use with various objects that you want to texture with the viewport.

  • RID get_viewport_rid ( ) const

Get the viewport RID from the VisualServer.

  • Rect2 get_visible_rect ( ) const

Return the final, visible rect in global screen coordinates.

Return the 2D world of the viewport.

  • Variant gui_get_drag_data ( ) const

Returns the drag data from the GUI, that was previously returned by Control.get_drag_data.

  • bool gui_has_modal_stack ( ) const

Returns whether there are shown modals on-screen.

  • bool is_size_override_enabled ( ) const

Get the enabled status of the size override set with set_size_override.

  • bool is_size_override_stretch_enabled ( ) const

Get the enabled status of the size strech override set with set_size_override_stretch.

  • void set_attach_to_screen_rect ( Rect2 rect )

Set the canvas transform of the viewport, useful for changing the on-screen positions of all child CanvasItems. This is relative to the global canvas transform of the viewport.

  • void set_global_canvas_transform ( Transform2D xform )

Set the global canvas transform of the viewport. The canvas transform is relative to this.

  • void set_size_override ( bool enable, Vector2 size=Vector2( -1, -1 ), Vector2 margin=Vector2( 0, 0 ) )

Set the size override of the viewport. If the enable parameter is true, it would use the override, otherwise it would use the default size. If the size parameter is equal to (-1, -1), it won’t update the size.

  • void set_size_override_stretch ( bool enabled )

Set whether the size override affects stretch as well.

  • void set_world_2d ( World2D world_2d )
  • void update_worlds ( )

Force update of the 2D and 3D worlds.

  • void warp_mouse ( Vector2 to_position )

Warp the mouse to a position, relative to the viewport.