Viewport¶
Category: Core
Brief Description¶
Creates a sub-view into the screen.
Member Functions¶
Signals¶
- size_changed ( )
Numeric Constants¶
- RENDER_TARGET_UPDATE_DISABLED = 0 — Do not update the render target.
- RENDER_TARGET_UPDATE_ONCE = 1 — Update the render target once, then switch to
RENDER_TARGET_UPDATE_DISABLED
- RENDER_TARGET_UPDATE_WHEN_VISIBLE = 2 — Update the render target only when it is visible. This is the default value.
- RENDER_TARGET_UPDATE_ALWAYS = 3 — Update the render target always.
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.
- World2D find_world_2d ( ) const
Return the 2D world of the viewport.
- Camera get_camera ( ) const
Return the active 3D camera.
- Matrix32 get_canvas_transform ( ) const
Get the canvas transform of the viewport.
- Matrix32 get_final_transform ( ) const
Get the total transform of the viewport.
- Matrix32 get_global_canvas_transform ( ) const
Get the global canvas transform of the viewport.
- Vector2 get_mouse_pos ( ) const
Get the mouse position, relative to the viewport.
- bool get_physics_object_picking ( )
Get whether picking for all physics objects inside the viewport is enabled.
- Rect2 get_rect ( ) const
Return the viewport rect. If the viewport is child of a control, it will use the same rect as the parent. Otherwise, if the rect is empty, the viewport will use all the allowed space.
- bool get_render_target_clear_on_new_frame ( ) const
Return whether automatic clearing of the render target on each frame is enabled.
- bool get_render_target_filter ( ) const
Get whether the rendered texture has filters enabled.
- bool get_render_target_gen_mipmaps ( ) const
Get whether the rendered texture will have mipmaps generated.
- RenderTargetTexture get_render_target_texture ( ) const
Get the render target’s texture, for use with various objects that you want to texture with the viewport.
- int get_render_target_update_mode ( ) const
Get when the render target would be updated, will be one of the RENDER_TARGET_UPDATE\_\*
constants.
- bool get_render_target_vflip ( ) const
Set whether the render target is flipped on the Y axis.
- Image get_screen_capture ( ) const
Return the captured screenshot after queue_screen_capture. You might need to check more than one frame untill the right image is returned.
- Vector2 get_size_override ( ) const
Get the size override set with set_size_override.
- RID get_viewport ( ) const
Get the viewport RID from the visual server.
- Rect2 get_visible_rect ( ) const
Return the final, visible rect in global screen coordinates.
- World get_world ( ) const
Return the 3D world of the viewport.
- bool gui_has_modal_stack ( ) const
Returs whether there are shown modals on-screen.
- bool has_transparent_background ( ) const
Return whether the viewport lets whatever is behind it to show.
- void input ( InputEvent local_event )
- bool is_audio_listener ( ) const
Returns whether the viewport sends sounds to the speakers.
- bool is_audio_listener_2d ( ) const
Returns whether the viewport sends soundsfrom 2D emitters to the speakers.
- bool is_input_disabled ( ) const
Return whether input to the viewport is disabled.
- bool is_set_as_render_target ( ) const
Return whether the viewport is set as a render target by set_as_render_target.
- 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.
- bool is_using_own_world ( ) const
Return whether the viewport is using a world separate from the parent viewport’s world.
- void queue_screen_capture ( )
Queue a multithreaded screenshot, you can retrive it at a later frame via get_screen_capture.
- void render_target_clear ( )
Clear the render target manually.
- void set_as_audio_listener ( bool enable )
Makes the viewport send sounds to the speakers.
- void set_as_audio_listener_2d ( bool enable )
Makes the viewport send sounds from 2D emitters to the speakers.
- void set_as_render_target ( bool enable )
Set the viewport’s render target mode.
- void set_canvas_transform ( Matrix32 xform )
Set the canvas transform of the viewport, useful for changing the on-screen positions of all child :ref:`CanvasItem<class_canvasitem>`s. This is relative to the global canvas transform of the viewport.
- void set_disable_input ( bool disable )
Set whether input to the viewport is disabled.
- void set_global_canvas_transform ( Matrix32 xform )
Set the global canvas transform of the viewport. The canvas transform is relative to this.
- void set_physics_object_picking ( bool enable )
Enable/disable picking for all physics objects inside the viewport.
- void set_rect ( Rect2 rect )
Set the viewport rect. If the viewport is child of a control, it will use the same rect as the parent.
- void set_render_target_clear_on_new_frame ( bool enable )
Enable/disable automatic clearing of the render target on each frame. You might find it better to disable this if you are using the viewport for rarely updated textures. To clear manually, check render_target_clear
- void set_render_target_filter ( bool enable )
Set whether the rendered texture should have filters enabled. Disable if you want the texture’s pixels be visible.
- void set_render_target_gen_mipmaps ( bool enable )
Set whether the rendered texture should have mipmaps generated. Mipmaps allow the texture to have better antialiasing from far away.
- void set_render_target_to_screen_rect ( Rect2 rect )
Map a part of the screen to the render target directly.
- void set_render_target_update_mode ( int mode )
Set when the render target should be updated, has to be one of the RENDER_TARGET_UPDATE\_\*
constants.
- void set_render_target_vflip ( bool enable )
Set whether the render target should be flipped on the Y axis.
Set the size 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_transparent_background ( bool enable )
If this viewport is a child of another viewport, keep the previously drawn background visible.
- void set_use_own_world ( bool enable )
Make the viewport use a world separate from the parent viewport’s world.
- void set_world ( World world )
Change the 3D world of the viewport.
- void unhandled_input ( InputEvent local_event )
- void update_worlds ( )
Force update of the 2D and 3D worlds.
- void warp_mouse ( Vector2 to_pos )
Wrap the mouse to a position, relative to the viewport.