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

    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.

    public bool EditorDrawDragMargin { get; set; }

If true, draws the camera’s drag margin rectangle in the editor.

    public bool EditorDrawLimits { get; set; }

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

    public bool EditorDrawScreen { get; set; }

If true, draws the camera’s screen rectangle in the editor.

    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.

    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.

Note: Offset H is used only to force offset relative to margins. It’s not updated in any way if drag margins are enabled and can be used to set initial offset.

    public float OffsetV { get; set; }

The vertical offset of the camera, relative to the drag margins.

Note: Used the same as OffsetH.

    public Camera2DProcessMode ProcessMode { get; set; }

    public bool Rotating { get; set; }

If true, the camera rotates with the target.

    public bool SmoothingEnabled { get; set; }

If true, the camera smoothly moves towards the target at SmoothingSpeed.

    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 2× zoom-in, and Vector2(4, 4) for a 4× zoom-out.

Methods

    public void Align()

Aligns the camera to the tracked node.

    public void ClearCurrent()

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

    public void ForceUpdateScroll()

Forces the camera to update scroll immediately.

    [Obsolete("GetAnchorMode is deprecated. Use the AnchorMode property instead.")]
    public AnchorModeEnum GetAnchorMode()

Getter for AnchorMode

    public Vector2 GetCameraPosition()

Returns the camera position.

    public Vector2 GetCameraScreenCenter()

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

    [Obsolete("GetCustomViewport is deprecated. Use the CustomViewport property instead.")]
    public Node GetCustomViewport()

Getter for CustomViewport

    [Obsolete("GetDragMargin is deprecated. Use the DragMarginBottom property instead.")]
    public float GetDragMargin(Margin margin)

    [Obsolete("GetFollowSmoothing is deprecated. Use the SmoothingSpeed property instead.")]
    public float GetFollowSmoothing()

Getter for SmoothingSpeed

    [Obsolete("GetHOffset is deprecated. Use the OffsetH property instead.")]
    public float GetHOffset()

Getter for OffsetH

    [Obsolete("GetLimit is deprecated. Use the LimitBottom property instead.")]
    public int GetLimit(Margin margin)

    [Obsolete("GetOffset is deprecated. Use the Offset property instead.")]
    public Vector2 GetOffset()

Getter for Offset

    [Obsolete("GetProcessMode is deprecated. Use the ProcessMode property instead.")]
    public Camera2DProcessMode GetProcessMode()

Getter for ProcessMode

    [Obsolete("GetVOffset is deprecated. Use the OffsetV property instead.")]
    public float GetVOffset()

Getter for OffsetV

    [Obsolete("GetZoom is deprecated. Use the Zoom property instead.")]
    public Vector2 GetZoom()

Getter for Zoom

    [Obsolete("IsCurrent is deprecated. Use the Current property instead.")]
    public bool IsCurrent()

Getter for Current

    [Obsolete("IsFollowSmoothingEnabled is deprecated. Use the SmoothingEnabled property instead.")]
    public bool IsFollowSmoothingEnabled()

Getter for SmoothingEnabled

    [Obsolete("IsHDragEnabled is deprecated. Use the DragMarginHEnabled property instead.")]
    public bool IsHDragEnabled()

Getter for DragMarginHEnabled

    [Obsolete("IsLimitDrawingEnabled is deprecated. Use the EditorDrawLimits property instead.")]
    public bool IsLimitDrawingEnabled()

Getter for EditorDrawLimits

    [Obsolete("IsLimitSmoothingEnabled is deprecated. Use the LimitSmoothed property instead.")]
    public bool IsLimitSmoothingEnabled()

Getter for LimitSmoothed

    [Obsolete("IsMarginDrawingEnabled is deprecated. Use the EditorDrawDragMargin property instead.")]
    public bool IsMarginDrawingEnabled()

Getter for EditorDrawDragMargin

    [Obsolete("IsRotating is deprecated. Use the Rotating property instead.")]
    public bool IsRotating()

Getter for Rotating

    [Obsolete("IsScreenDrawingEnabled is deprecated. Use the EditorDrawScreen property instead.")]
    public bool IsScreenDrawingEnabled()

Getter for EditorDrawScreen

    [Obsolete("IsVDragEnabled is deprecated. Use the DragMarginVEnabled property instead.")]
    public bool IsVDragEnabled()

Getter for DragMarginVEnabled

    public void MakeCurrent()

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

    public void ResetSmoothing()

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

This has no effect if smoothing is disabled.

    [Obsolete("SetAnchorMode is deprecated. Use the AnchorMode property instead.")]
    public void SetAnchorMode(AnchorModeEnum anchorMode)

Setter for AnchorMode

    [Obsolete("SetCustomViewport is deprecated. Use the CustomViewport property instead.")]
    public void SetCustomViewport(Node viewport)

Setter for CustomViewport

    [Obsolete("SetDragMargin is deprecated. Use the DragMarginBottom property instead.")]
    public void SetDragMargin(Margin margin, float dragMargin)

    [Obsolete("SetEnableFollowSmoothing is deprecated. Use the SmoothingEnabled property instead.")]
    public void SetEnableFollowSmoothing(bool followSmoothing)

Setter for SmoothingEnabled

    [Obsolete("SetFollowSmoothing is deprecated. Use the SmoothingSpeed property instead.")]
    public void SetFollowSmoothing(float followSmoothing)

Setter for SmoothingSpeed

    [Obsolete("SetHDragEnabled is deprecated. Use the DragMarginHEnabled property instead.")]
    public void SetHDragEnabled(bool enabled)

Setter for DragMarginHEnabled

    [Obsolete("SetHOffset is deprecated. Use the OffsetH property instead.")]
    public void SetHOffset(float ofs)

Setter for OffsetH

    [Obsolete("SetLimit is deprecated. Use the LimitBottom property instead.")]
    public void SetLimit(Margin margin, int limit)

    [Obsolete("SetLimitDrawingEnabled is deprecated. Use the EditorDrawLimits property instead.")]
    public void SetLimitDrawingEnabled(bool limitDrawingEnabled)

Setter for EditorDrawLimits

    [Obsolete("SetLimitSmoothingEnabled is deprecated. Use the LimitSmoothed property instead.")]
    public void SetLimitSmoothingEnabled(bool limitSmoothingEnabled)

Setter for LimitSmoothed

    [Obsolete("SetMarginDrawingEnabled is deprecated. Use the EditorDrawDragMargin property instead.")]
    public void SetMarginDrawingEnabled(bool marginDrawingEnabled)

Setter for EditorDrawDragMargin

    [Obsolete("SetOffset is deprecated. Use the Offset property instead.")]
    public void SetOffset(Vector2 offset)

Setter for Offset

    [Obsolete("SetProcessMode is deprecated. Use the ProcessMode property instead.")]
    public void SetProcessMode(Camera2DProcessMode mode)

Setter for ProcessMode

    [Obsolete("SetRotating is deprecated. Use the Rotating property instead.")]
    public void SetRotating(bool rotating)

Setter for Rotating

    [Obsolete("SetScreenDrawingEnabled is deprecated. Use the EditorDrawScreen property instead.")]
    public void SetScreenDrawingEnabled(bool screenDrawingEnabled)

Setter for EditorDrawScreen

    [Obsolete("SetVDragEnabled is deprecated. Use the DragMarginVEnabled property instead.")]
    public void SetVDragEnabled(bool enabled)

Setter for DragMarginVEnabled

    [Obsolete("SetVOffset is deprecated. Use the OffsetV property instead.")]
    public void SetVOffset(float ofs)

Setter for OffsetV

    [Obsolete("SetZoom is deprecated. Use the Zoom property instead.")]
    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: