Camera node for 2D scenes.
    public class Camera2D : Node2D

Camera node for 2D scenes. It forces the screen (current layer) to scroll following this node. This makes it easier (and faster) to program scrollable scenes than manually changing the position of CanvasItem based nodes.

This node is intended to be a simple helper to get things going quickly and it may happen often that more functionality is desired to change how the camera works. To make your own custom camera node, simply inherit from Node2D and change the transform of the canvas by calling get_viewport().set_canvas_transform(m) in Viewport.

Inheritance Chain

Constructors

    public Camera2D()

Properties

    public AnchorModeEnum AnchorMode { get; set; }

The Camera2D’s anchor point. See ANCHOR_MODE_* constants.

    public bool Current { get; set; }

If true, the camera is the active camera for the current scene. Only one camera can be current, so setting a different camera current will disable this one.

    public Node CustomViewport { get; set; }

The custom Viewport node attached to the Camera2D. If null or not a Viewport, uses the default viewport instead.

    public float DragMarginBottom { get; set; }

Bottom margin needed to drag the camera. A value of 1 makes the camera move only when reaching the edge of the screen.

    public bool DragMarginHEnabled { get; set; }

If true, the camera only moves when reaching the horizontal drag margins. If false, the camera moves horizontally regardless of margins. Default value: true.

    public float DragMarginLeft { get; set; }

Left margin needed to drag the camera. A value of 1 makes the camera move only when reaching the edge of the screen.

    public float DragMarginRight { get; set; }

Right margin needed to drag the camera. A value of 1 makes the camera move only when reaching the edge of the screen.

    public float DragMarginTop { get; set; }

Top margin needed to drag the camera. A value of 1 makes the camera move only when reaching the edge of the screen.

    public bool DragMarginVEnabled { get; set; }

If true, the camera only moves when reaching the vertical drag margins. If false, the camera moves vertically regardless of margins. Default value: true.

    public bool EditorDrawDragMargin { get; set; }

If true, draws the camera’s drag margin rectangle in the editor. Default value: false

    public bool EditorDrawLimits { get; set; }

If true, draws the camera’s limits rectangle in the editor. Default value: true

    public bool EditorDrawScreen { get; set; }

If true, draws the camera’s screen rectangle in the editor. Default value: false

    public int LimitBottom { get; set; }

Bottom scroll limit in pixels. The camera stops moving when reaching this value.

    public int LimitLeft { get; set; }

Left scroll limit in pixels. The camera stops moving when reaching this value.

    public int LimitRight { get; set; }

Right scroll limit in pixels. The camera stops moving when reaching this value.

    public bool LimitSmoothed { get; set; }

If true, the camera smoothly stops when reaches its limits. Default value: false

    public int LimitTop { get; set; }

Top scroll limit in pixels. The camera stops moving when reaching this value.

    public Vector2 Offset { get; set; }

The camera’s offset, useful for looking around or camera shake animations.

    public float OffsetH { get; set; }

The horizontal offset of the camera, relative to the drag margins. Default value: 0

    public float OffsetV { get; set; }

The vertical offset of the camera, relative to the drag margins. Default value: 0

    public Camera2DProcessMode ProcessMode { get; set; }

    public bool Rotating { get; set; }

If true, the camera rotates with the target. Default value: false

    public bool SmoothingEnabled { get; set; }

If true, the camera smoothly moves towards the target at SmoothingSpeed. Default value: false

    public float SmoothingSpeed { get; set; }

Speed in pixels per second of the camera’s smoothing effect when SmoothingEnabled is true

    public Vector2 Zoom { get; set; }

The camera’s zoom relative to the viewport. Values larger than Vector2(1, 1) zoom out and smaller values zoom in. For an example, use Vector2(0.5, 0.5) for a 2x zoom in, and Vector2(4, 4) for a 4x zoom out.

Methods

    public void Align()

Align the camera to the tracked node

    public void ClearCurrent()

Removes any Camera2D from the ancestor Viewport’s internal currently-assigned camera.

    public void ForceUpdateScroll()

Force the camera to update scroll immediately.

    public AnchorModeEnum GetAnchorMode()

Getter for AnchorMode

    public Vector2 GetCameraPosition()

Return the camera position.

    public Vector2 GetCameraScreenCenter()

Returns the location of the Camera2D’s screen-center, relative to the origin.

    public Node GetCustomViewport()

Getter for CustomViewport

    public float GetDragMargin(Margin margin)

    public float GetFollowSmoothing()

Getter for SmoothingSpeed

    public float GetHOffset()

Getter for OffsetH

    public int GetLimit(Margin margin)

    public Vector2 GetOffset()

Getter for Offset

    public Camera2DProcessMode GetProcessMode()

Getter for ProcessMode

    public float GetVOffset()

Getter for OffsetV

    public Vector2 GetZoom()

Getter for Zoom

    public bool IsCurrent()

Getter for Current

    public bool IsFollowSmoothingEnabled()

Getter for SmoothingEnabled

    public bool IsHDragEnabled()

Getter for DragMarginHEnabled

    public bool IsLimitDrawingEnabled()

Getter for EditorDrawLimits

    public bool IsLimitSmoothingEnabled()

Getter for LimitSmoothed

    public bool IsMarginDrawingEnabled()

Getter for EditorDrawDragMargin

    public bool IsRotating()

Getter for Rotating

    public bool IsScreenDrawingEnabled()

Getter for EditorDrawScreen

    public bool IsVDragEnabled()

Getter for DragMarginVEnabled

    public void MakeCurrent()

Make this the current 2D camera for the scene (viewport and layer), in case there’s many cameras in the scene.

    public void ResetSmoothing()

Set the camera’s position immediately to its current smoothing destination.

This has no effect if smoothing is disabled.

    public void SetAnchorMode(AnchorModeEnum anchorMode)

Setter for AnchorMode

    public void SetCustomViewport(Node viewport)

Setter for CustomViewport

    public void SetDragMargin(Margin margin, float dragMargin)

    public void SetEnableFollowSmoothing(bool followSmoothing)

Setter for SmoothingEnabled

    public void SetFollowSmoothing(float followSmoothing)

Setter for SmoothingSpeed

    public void SetHDragEnabled(bool enabled)

Setter for DragMarginHEnabled

    public void SetHOffset(float ofs)

Setter for OffsetH

    public void SetLimit(Margin margin, int limit)

    public void SetLimitDrawingEnabled(bool limitDrawingEnabled)

Setter for EditorDrawLimits

    public void SetLimitSmoothingEnabled(bool limitSmoothingEnabled)

Setter for LimitSmoothed

    public void SetMarginDrawingEnabled(bool marginDrawingEnabled)

Setter for EditorDrawDragMargin

    public void SetOffset(Vector2 offset)

Setter for Offset

    public void SetProcessMode(Camera2DProcessMode mode)

Setter for ProcessMode

    public void SetRotating(bool rotating)

Setter for Rotating

    public void SetScreenDrawingEnabled(bool screenDrawingEnabled)

Setter for EditorDrawScreen

    public void SetVDragEnabled(bool enabled)

Setter for DragMarginVEnabled

    public void SetVOffset(float ofs)

Setter for OffsetV

    public void SetZoom(Vector2 zoom)

Setter for Zoom

Inner Types

AnchorModeEnum

Name Value Description
FixedTopLeft 0 The camera’s position is fixed so that the top-left corner is always at the origin.
DragCenter 1 The camera’s position takes into account vertical/horizontal offsets and the screen size.

Camera2DProcessMode

Name Value Description
Physics 0  
Idle 1  
Tags: