:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Camera2D.xml. .. _class_Camera2D: Camera2D ======== **Inherits:** :ref:`Node2D` **<** :ref:`CanvasItem` **<** :ref:`Node` **<** :ref:`Object` Camera node for 2D scenes. .. rst-class:: classref-introduction-group Description ----------- 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 :ref:`CanvasItem`-based nodes. This node is intended to be a simple helper to get things going quickly, but more functionality may be desired to change how the camera works. To make your own custom camera node, inherit it from :ref:`Node2D` and change the transform of the canvas by setting :ref:`Viewport.canvas_transform` in :ref:`Viewport` (you can obtain the current :ref:`Viewport` by using :ref:`Node.get_viewport`). Note that the **Camera2D** node's ``position`` doesn't represent the actual position of the screen, which may differ due to applied smoothing or limits. You can use :ref:`get_camera_screen_center` to get the real position. .. rst-class:: classref-introduction-group Tutorials --------- - `2D Platformer Demo `__ - `2D Isometric Demo `__ - `2D HDR Demo `__ .. rst-class:: classref-reftable-group Properties ---------- .. table:: :widths: auto +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`AnchorMode` | :ref:`anchor_mode` | ``1`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`current` | ``false`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`Node` | :ref:`custom_viewport` | | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`drag_margin_bottom` | ``0.2`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`drag_margin_h_enabled` | ``false`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`drag_margin_left` | ``0.2`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`drag_margin_right` | ``0.2`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`drag_margin_top` | ``0.2`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`drag_margin_v_enabled` | ``false`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`editor_draw_drag_margin` | ``false`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`editor_draw_limits` | ``false`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`editor_draw_screen` | ``true`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`int` | :ref:`limit_bottom` | ``10000000`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`int` | :ref:`limit_left` | ``-10000000`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`int` | :ref:`limit_right` | ``10000000`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`limit_smoothed` | ``false`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`int` | :ref:`limit_top` | ``-10000000`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`Vector2` | :ref:`offset` | ``Vector2( 0, 0 )`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`offset_h` | ``0.0`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`offset_v` | ``0.0`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`Camera2DProcessMode` | :ref:`process_mode` | ``1`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`rotating` | ``false`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`bool` | :ref:`smoothing_enabled` | ``false`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`float` | :ref:`smoothing_speed` | ``5.0`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ | :ref:`Vector2` | :ref:`zoom` | ``Vector2( 1, 1 )`` | +---------------------------------------------------------------+---------------------------------------------------------------------------------+---------------------+ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`align` **(** **)** | +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear_current` **(** **)** | +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`force_update_scroll` **(** **)** | +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_camera_position` **(** **)** |const| | +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_camera_screen_center` **(** **)** |const| | +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`get_drag_margin` **(** :ref:`Margin` margin **)** |const| | +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_limit` **(** :ref:`Margin` margin **)** |const| | +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`make_current` **(** **)** | +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`reset_smoothing` **(** **)** | +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_drag_margin` **(** :ref:`Margin` margin, :ref:`float` drag_margin **)** | +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_limit` **(** :ref:`Margin` margin, :ref:`int` limit **)** | +-------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Enumerations ------------ .. _enum_Camera2D_AnchorMode: .. rst-class:: classref-enumeration enum **AnchorMode**: .. _class_Camera2D_constant_ANCHOR_MODE_FIXED_TOP_LEFT: .. rst-class:: classref-enumeration-constant :ref:`AnchorMode` **ANCHOR_MODE_FIXED_TOP_LEFT** = ``0`` The camera's position is fixed so that the top-left corner is always at the origin. .. _class_Camera2D_constant_ANCHOR_MODE_DRAG_CENTER: .. rst-class:: classref-enumeration-constant :ref:`AnchorMode` **ANCHOR_MODE_DRAG_CENTER** = ``1`` The camera's position takes into account vertical/horizontal offsets and the screen size. .. rst-class:: classref-item-separator ---- .. _enum_Camera2D_Camera2DProcessMode: .. rst-class:: classref-enumeration enum **Camera2DProcessMode**: .. _class_Camera2D_constant_CAMERA2D_PROCESS_PHYSICS: .. rst-class:: classref-enumeration-constant :ref:`Camera2DProcessMode` **CAMERA2D_PROCESS_PHYSICS** = ``0`` The camera updates with the ``_physics_process`` callback. .. _class_Camera2D_constant_CAMERA2D_PROCESS_IDLE: .. rst-class:: classref-enumeration-constant :ref:`Camera2DProcessMode` **CAMERA2D_PROCESS_IDLE** = ``1`` The camera updates with the ``_process`` callback. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Property Descriptions --------------------- .. _class_Camera2D_property_anchor_mode: .. rst-class:: classref-property :ref:`AnchorMode` **anchor_mode** = ``1`` .. rst-class:: classref-property-setget - void **set_anchor_mode** **(** :ref:`AnchorMode` value **)** - :ref:`AnchorMode` **get_anchor_mode** **(** **)** The Camera2D's anchor point. See :ref:`AnchorMode` constants. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_current: .. rst-class:: classref-property :ref:`bool` **current** = ``false`` .. rst-class:: classref-property-setget - :ref:`bool` **is_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. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_custom_viewport: .. rst-class:: classref-property :ref:`Node` **custom_viewport** .. rst-class:: classref-property-setget - void **set_custom_viewport** **(** :ref:`Node` value **)** - :ref:`Node` **get_custom_viewport** **(** **)** The custom :ref:`Viewport` node attached to the **Camera2D**. If ``null`` or not a :ref:`Viewport`, uses the default viewport instead. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_drag_margin_bottom: .. rst-class:: classref-property :ref:`float` **drag_margin_bottom** = ``0.2`` .. rst-class:: classref-property-setget - void **set_drag_margin** **(** :ref:`Margin` margin, :ref:`float` drag_margin **)** - :ref:`float` **get_drag_margin** **(** :ref:`Margin` margin **)** |const| Bottom margin needed to drag the camera. A value of ``1`` makes the camera move only when reaching the edge of the screen. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_drag_margin_h_enabled: .. rst-class:: classref-property :ref:`bool` **drag_margin_h_enabled** = ``false`` .. rst-class:: classref-property-setget - void **set_h_drag_enabled** **(** :ref:`bool` value **)** - :ref:`bool` **is_h_drag_enabled** **(** **)** If ``true``, the camera only moves when reaching the horizontal drag margins. If ``false``, the camera moves horizontally regardless of margins. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_drag_margin_left: .. rst-class:: classref-property :ref:`float` **drag_margin_left** = ``0.2`` .. rst-class:: classref-property-setget - void **set_drag_margin** **(** :ref:`Margin` margin, :ref:`float` drag_margin **)** - :ref:`float` **get_drag_margin** **(** :ref:`Margin` margin **)** |const| Left margin needed to drag the camera. A value of ``1`` makes the camera move only when reaching the edge of the screen. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_drag_margin_right: .. rst-class:: classref-property :ref:`float` **drag_margin_right** = ``0.2`` .. rst-class:: classref-property-setget - void **set_drag_margin** **(** :ref:`Margin` margin, :ref:`float` drag_margin **)** - :ref:`float` **get_drag_margin** **(** :ref:`Margin` margin **)** |const| Right margin needed to drag the camera. A value of ``1`` makes the camera move only when reaching the edge of the screen. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_drag_margin_top: .. rst-class:: classref-property :ref:`float` **drag_margin_top** = ``0.2`` .. rst-class:: classref-property-setget - void **set_drag_margin** **(** :ref:`Margin` margin, :ref:`float` drag_margin **)** - :ref:`float` **get_drag_margin** **(** :ref:`Margin` margin **)** |const| Top margin needed to drag the camera. A value of ``1`` makes the camera move only when reaching the edge of the screen. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_drag_margin_v_enabled: .. rst-class:: classref-property :ref:`bool` **drag_margin_v_enabled** = ``false`` .. rst-class:: classref-property-setget - void **set_v_drag_enabled** **(** :ref:`bool` value **)** - :ref:`bool` **is_v_drag_enabled** **(** **)** If ``true``, the camera only moves when reaching the vertical drag margins. If ``false``, the camera moves vertically regardless of margins. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_editor_draw_drag_margin: .. rst-class:: classref-property :ref:`bool` **editor_draw_drag_margin** = ``false`` .. rst-class:: classref-property-setget - void **set_margin_drawing_enabled** **(** :ref:`bool` value **)** - :ref:`bool` **is_margin_drawing_enabled** **(** **)** If ``true``, draws the camera's drag margin rectangle in the editor. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_editor_draw_limits: .. rst-class:: classref-property :ref:`bool` **editor_draw_limits** = ``false`` .. rst-class:: classref-property-setget - void **set_limit_drawing_enabled** **(** :ref:`bool` value **)** - :ref:`bool` **is_limit_drawing_enabled** **(** **)** If ``true``, draws the camera's limits rectangle in the editor. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_editor_draw_screen: .. rst-class:: classref-property :ref:`bool` **editor_draw_screen** = ``true`` .. rst-class:: classref-property-setget - void **set_screen_drawing_enabled** **(** :ref:`bool` value **)** - :ref:`bool` **is_screen_drawing_enabled** **(** **)** If ``true``, draws the camera's screen rectangle in the editor. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_limit_bottom: .. rst-class:: classref-property :ref:`int` **limit_bottom** = ``10000000`` .. rst-class:: classref-property-setget - void **set_limit** **(** :ref:`Margin` margin, :ref:`int` limit **)** - :ref:`int` **get_limit** **(** :ref:`Margin` margin **)** |const| Bottom scroll limit in pixels. The camera stops moving when reaching this value. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_limit_left: .. rst-class:: classref-property :ref:`int` **limit_left** = ``-10000000`` .. rst-class:: classref-property-setget - void **set_limit** **(** :ref:`Margin` margin, :ref:`int` limit **)** - :ref:`int` **get_limit** **(** :ref:`Margin` margin **)** |const| Left scroll limit in pixels. The camera stops moving when reaching this value. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_limit_right: .. rst-class:: classref-property :ref:`int` **limit_right** = ``10000000`` .. rst-class:: classref-property-setget - void **set_limit** **(** :ref:`Margin` margin, :ref:`int` limit **)** - :ref:`int` **get_limit** **(** :ref:`Margin` margin **)** |const| Right scroll limit in pixels. The camera stops moving when reaching this value. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_limit_smoothed: .. rst-class:: classref-property :ref:`bool` **limit_smoothed** = ``false`` .. rst-class:: classref-property-setget - void **set_limit_smoothing_enabled** **(** :ref:`bool` value **)** - :ref:`bool` **is_limit_smoothing_enabled** **(** **)** If ``true``, the camera smoothly stops when reaches its limits. This property has no effect if :ref:`smoothing_enabled` is ``false``. \ **Note:** To immediately update the camera's position to be within limits without smoothing, even with this setting enabled, invoke :ref:`reset_smoothing`. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_limit_top: .. rst-class:: classref-property :ref:`int` **limit_top** = ``-10000000`` .. rst-class:: classref-property-setget - void **set_limit** **(** :ref:`Margin` margin, :ref:`int` limit **)** - :ref:`int` **get_limit** **(** :ref:`Margin` margin **)** |const| Top scroll limit in pixels. The camera stops moving when reaching this value. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_offset: .. rst-class:: classref-property :ref:`Vector2` **offset** = ``Vector2( 0, 0 )`` .. rst-class:: classref-property-setget - void **set_offset** **(** :ref:`Vector2` value **)** - :ref:`Vector2` **get_offset** **(** **)** The camera's offset, useful for looking around or camera shake animations. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_offset_h: .. rst-class:: classref-property :ref:`float` **offset_h** = ``0.0`` .. rst-class:: classref-property-setget - void **set_h_offset** **(** :ref:`float` value **)** - :ref:`float` **get_h_offset** **(** **)** 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. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_offset_v: .. rst-class:: classref-property :ref:`float` **offset_v** = ``0.0`` .. rst-class:: classref-property-setget - void **set_v_offset** **(** :ref:`float` value **)** - :ref:`float` **get_v_offset** **(** **)** The vertical offset of the camera, relative to the drag margins. \ **Note:** Used the same as :ref:`offset_h`. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_process_mode: .. rst-class:: classref-property :ref:`Camera2DProcessMode` **process_mode** = ``1`` .. rst-class:: classref-property-setget - void **set_process_mode** **(** :ref:`Camera2DProcessMode` value **)** - :ref:`Camera2DProcessMode` **get_process_mode** **(** **)** The camera's process callback. See :ref:`Camera2DProcessMode`. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_rotating: .. rst-class:: classref-property :ref:`bool` **rotating** = ``false`` .. rst-class:: classref-property-setget - void **set_rotating** **(** :ref:`bool` value **)** - :ref:`bool` **is_rotating** **(** **)** If ``true``, the camera view rotates with the target. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_smoothing_enabled: .. rst-class:: classref-property :ref:`bool` **smoothing_enabled** = ``false`` .. rst-class:: classref-property-setget - void **set_enable_follow_smoothing** **(** :ref:`bool` value **)** - :ref:`bool` **is_follow_smoothing_enabled** **(** **)** If ``true``, the camera smoothly moves towards the target at :ref:`smoothing_speed`. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_smoothing_speed: .. rst-class:: classref-property :ref:`float` **smoothing_speed** = ``5.0`` .. rst-class:: classref-property-setget - void **set_follow_smoothing** **(** :ref:`float` value **)** - :ref:`float` **get_follow_smoothing** **(** **)** Speed in pixels per second of the camera's smoothing effect when :ref:`smoothing_enabled` is ``true``. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_property_zoom: .. rst-class:: classref-property :ref:`Vector2` **zoom** = ``Vector2( 1, 1 )`` .. rst-class:: classref-property-setget - void **set_zoom** **(** :ref:`Vector2` value **)** - :ref:`Vector2` **get_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 2× zoom-in, and ``Vector2(4, 4)`` for a 4× zoom-out. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_Camera2D_method_align: .. rst-class:: classref-method void **align** **(** **)** Aligns the camera to the tracked node. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_method_clear_current: .. rst-class:: classref-method void **clear_current** **(** **)** Removes any **Camera2D** from the ancestor :ref:`Viewport`'s internal currently-assigned camera. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_method_force_update_scroll: .. rst-class:: classref-method void **force_update_scroll** **(** **)** Forces the camera to update scroll immediately. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_method_get_camera_position: .. rst-class:: classref-method :ref:`Vector2` **get_camera_position** **(** **)** |const| Returns the camera's ``position`` (the tracked point the camera attempts to follow), relative to the origin. \ **Note:** The returned value is not the same as :ref:`Node2D.position` or :ref:`Node2D.global_position`, as it is affected by the ``drag`` properties. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_method_get_camera_screen_center: .. rst-class:: classref-method :ref:`Vector2` **get_camera_screen_center** **(** **)** |const| Returns the location of the **Camera2D**'s screen-center, relative to the origin. \ **Note:** The real ``position`` of the camera may be different, see :ref:`get_camera_position`. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_method_get_drag_margin: .. rst-class:: classref-method :ref:`float` **get_drag_margin** **(** :ref:`Margin` margin **)** |const| Returns the specified margin. See also :ref:`drag_margin_bottom`, :ref:`drag_margin_top`, :ref:`drag_margin_left`, and :ref:`drag_margin_right`. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_method_get_limit: .. rst-class:: classref-method :ref:`int` **get_limit** **(** :ref:`Margin` margin **)** |const| Returns the specified camera limit. See also :ref:`limit_bottom`, :ref:`limit_top`, :ref:`limit_left`, and :ref:`limit_right`. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_method_make_current: .. rst-class:: classref-method void **make_current** **(** **)** Make this the current 2D camera for the scene (viewport and layer), in case there are many cameras in the scene. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_method_reset_smoothing: .. rst-class:: classref-method void **reset_smoothing** **(** **)** Sets the camera's position immediately to its current smoothing destination. This method has no effect if :ref:`smoothing_enabled` is ``false``. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_method_set_drag_margin: .. rst-class:: classref-method void **set_drag_margin** **(** :ref:`Margin` margin, :ref:`float` drag_margin **)** Sets the specified margin. See also :ref:`drag_margin_bottom`, :ref:`drag_margin_top`, :ref:`drag_margin_left`, and :ref:`drag_margin_right`. .. rst-class:: classref-item-separator ---- .. _class_Camera2D_method_set_limit: .. rst-class:: classref-method void **set_limit** **(** :ref:`Margin` margin, :ref:`int` limit **)** Sets the specified camera limit. See also :ref:`limit_bottom`, :ref:`limit_top`, :ref:`limit_left`, and :ref:`limit_right`. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`