Skip to main content

Viewport

Inherits: Node < Object

Description

Abstract base class for viewports. Encapsulates drawing and interaction with a game world. A Viewport creates a different view into the screen, or a sub-view inside another viewport.

Properties

transparent_bg
bool
default:"false"
If true, the viewport should render its background as transparent.
msaa_2d
MSAA
default:"MSAA_DISABLED"
The multisample antialiasing mode for 2D/Canvas rendering.
msaa_3d
MSAA
default:"MSAA_DISABLED"
The multisample antialiasing mode for 3D rendering.

Methods

get_camera_2d

Camera2D get_camera_2d()
Returns the currently active 2D camera.

get_camera_3d

Camera3D get_camera_3d()
Returns the currently active 3D camera.

get_mouse_position

Vector2 get_mouse_position()
Returns the mouse’s position in this Viewport.

get_texture

ViewportTexture get_texture()
Returns the viewport’s texture.

set_input_as_handled

void set_input_as_handled()
Stops the input from propagating further up the SceneTree.

Signals

size_changed()

Emitted when the size of the viewport is changed.

Example Usage

var viewport = get_viewport()
var mouse_pos = viewport.get_mouse_position()
print("Mouse at: ", mouse_pos)

# Get viewport texture
var texture = viewport.get_texture()

Build docs developers (and LLMs) love