Camera2D

Inherits: Node2D < CanvasItem < Node < Object

Category: Core

Brief Description

Camera node for 2D scenes.

Properties

AnchorModeanchor_mode
boolcurrent
Nodecustom_viewport
floatdrag_margin_bottom
booldrag_margin_h_enabled
floatdrag_margin_left
floatdrag_margin_right
floatdrag_margin_top
booldrag_margin_v_enabled
booleditor_draw_drag_margin
booleditor_draw_limits
booleditor_draw_screen
intlimit_bottom
intlimit_left
intlimit_right
boollimit_smoothed
intlimit_top
Vector2offset
floatoffset_h
floatoffset_v
Camera2DProcessModeprocess_mode
boolrotating
boolsmoothing_enabled
floatsmoothing_speed
Vector2zoom

Methods

voidalign ( )
voidclear_current ( )
voidforce_update_scroll ( )
Vector2get_camera_position ( ) const
Vector2get_camera_screen_center ( ) const
voidmake_current ( )
voidreset_smoothing ( )

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

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

Property Descriptions

Setterset_anchor_mode(value)
Getterget_anchor_mode()

The Camera2D’s anchor point. See ANCHOR_MODE_* 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.


  • Node custom_viewport
Setterset_custom_viewport(value)
Getterget_custom_viewport()

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


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


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()

Right 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()

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 true, the camera only moves when reaching the vertical drag margins. If false, the camera moves vertically regardless of margins. Default value: true.


  • bool 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


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


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


  • bool limit_smoothed
Setterset_limit_smoothing_enabled(value)
Getteris_limit_smoothing_enabled()

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


Setterset_limit(value)
Getterget_limit()

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.


Setterset_h_offset(value)
Getterget_h_offset()

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


Setterset_v_offset(value)
Getterget_v_offset()

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


Setterset_process_mode(value)
Getterget_process_mode()

Setterset_rotating(value)
Getteris_rotating()

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


  • bool 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


Setterset_follow_smoothing(value)
Getterget_follow_smoothing()

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


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.

Method Descriptions

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


  • Vector2 get_camera_position ( ) const

Returns the camera position.


  • Vector2 get_camera_screen_center ( ) const

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


  • void make_current ( )

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.