Camera2D

    Category: Core

    Camera node for 2D scenes.

    Properties

    void ( )
    voidclear_current ( )
    void ( )
    Vector2 ( ) const
    Vector2 ( ) const
    voidmake_current ( )
    void ( )

    Enumerations

    enum AnchorMode:

    • ANCHOR_MODE_FIXED_TOP_LEFT = 0 — The camera’s position is fixed so that the top-left corner is always at the origin.
    • ANCHOR_MODE_DRAG_CENTER = 1 — The camera’s position takes into account vertical/horizontal offsets and the screen size.

    enum Camera2DProcessMode:

    • CAMERA2D_PROCESS_PHYSICS = 0
    • CAMERA2D_PROCESS_IDLE = 1

    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 and change the transform of the canvas by calling get_viewport().set_canvas_transform(m) in Viewport.

    Property Descriptions

    • anchor_mode
    Setterset_anchor_mode(value)
    Getterget_anchor_mode()

    The Camera2D’s anchor point. See constants.


    Getteris_current()

    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.


    Setterset_custom_viewport(value)
    Getterget_custom_viewport()

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


    • drag_margin_bottom
    Setterset_drag_margin(value)
    Getterget_drag_margin()

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


    • bool drag_margin_h_enabled
    Setterset_h_drag_enabled(value)
    Getteris_h_drag_enabled()

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


    • drag_margin_left
    Setterset_drag_margin(value)
    Getterget_drag_margin()

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


    Setterset_drag_margin(value)
    Getterget_drag_margin()

    • drag_margin_top

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


    • bool drag_margin_v_enabled
    Setterset_v_drag_enabled(value)
    Getteris_v_drag_enabled()

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


    • editor_draw_drag_margin
    Setterset_margin_drawing_enabled(value)
    Getteris_margin_drawing_enabled()

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


    • bool editor_draw_limits
    Setterset_limit_drawing_enabled(value)
    Getteris_limit_drawing_enabled()

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


    • editor_draw_screen
    Setterset_screen_drawing_enabled(value)
    Getteris_screen_drawing_enabled()

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


    • int limit_bottom
    Setterset_limit(value)
    Getterget_limit()

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


    • limit_left
    Setterset_limit(value)
    Getterget_limit()

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


    • int limit_right
    Setterset_limit(value)
    Getterget_limit()

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


    • limit_smoothed
    Setterset_limit_smoothing_enabled(value)
    Getteris_limit_smoothing_enabled()

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


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


    Setterset_offset(value)
    Getterget_offset()

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


    • offset_h
    Setterset_h_offset(value)
    Getterget_h_offset()

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


    Setterset_v_offset(value)
    Getterget_v_offset()

    • process_mode
    Setterset_process_mode(value)
    Getterget_process_mode()

    Setterset_rotating(value)
    Getteris_rotating()

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


    • smoothing_enabled
    Setterset_enable_follow_smoothing(value)
    Getteris_follow_smoothing_enabled()

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


    • smoothing_speed
    Setterset_follow_smoothing(value)
    Getterget_follow_smoothing()

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


    • zoom
    Setterset_zoom(value)
    Getterget_zoom()

    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.

    • void align ( )

    Align the camera to the tracked node


    • void clear_current ( )

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


    • void force_update_scroll ( )

    Force the camera to update scroll immediately.


    • get_camera_position ( ) const

    Returns the camera position.


    • Vector2 get_camera_screen_center ( ) const

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


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


    • void reset_smoothing ( )

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

    This has no effect if smoothing is disabled.