Camera2D
Inherits: Node2D < CanvasItem < Node < Object Camera node for 2D scenes.
Description
CanvasItem-based nodes.
Node2D and change the transform of the canvas by setting Viewport.canvas_transform in Viewport (you can obtain the current Viewport by using Node.get_viewport).
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 get_camera_screen_center to get the real position.
Tutorials
- 2D Platformer Demo
- 2D Isometric Demo
- 2D HDR Demo
Properties
Methods
Enumerations
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.
Camera2DProcessMode:
- CAMERA2D_PROCESS_PHYSICS = 0 —- The camera updates with the
_physics_processcallback. - CAMERA2D_PROCESS_IDLE = 1 —- The camera updates with the
_processcallback.Property Descriptions
- AnchorMode anchor_mode AnchorMode constants.
- bool current
true, the camera is the active camera for the current scene. Only one camera can be current, so setting a different cameracurrentwill disable this one.
- Node custom_viewport
Viewport node attached to the
Camera2D. Ifnullor not a Viewport, uses the default viewport instead.
- float drag_margin_bottom
1makes the camera move only when reaching the edge of the screen.
- bool drag_margin_h_enabled
true, the camera only moves when reaching the horizontal drag margins. Iffalse, the camera moves horizontally regardless of margins.
- float drag_margin_left
1makes the camera move only when reaching the edge of the screen.
- float drag_margin_right
1makes the camera move only when reaching the edge of the screen.
- float drag_margin_top
1makes the camera move only when reaching the edge of the screen.
- bool drag_margin_v_enabled
true, the camera only moves when reaching the vertical drag margins. Iffalse, the camera moves vertically regardless of margins.
- bool editor_draw_drag_margin
true, draws the camera’s drag margin rectangle in the editor.
- bool editor_draw_limits
true, draws the camera’s limits rectangle in the editor.
- bool editor_draw_screen
true, draws the camera’s screen rectangle in the editor.
- int limit_bottom Bottom scroll limit in pixels. The camera stops moving when reaching this value.
- int limit_left Left scroll limit in pixels. The camera stops moving when reaching this value.
- int limit_right Right scroll limit in pixels. The camera stops moving when reaching this value.
- bool limit_smoothed
true, the camera smoothly stops when reaches its limits. smoothing_enabled isfalse. Note: To immediately update the camera’s position to be within limits without smoothing, even with this setting enabled, invoke reset_smoothing.
- int limit_top Top scroll limit in pixels. The camera stops moving when reaching this value.
- Vector2 offset The camera’s offset, useful for looking around or camera shake animations.
- float offset_h 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.
- float offset_v The vertical offset of the camera, relative to the drag margins. Note: Used the same as offset_h.
- Camera2DProcessMode process_mode Camera2DProcessMode.
- bool rotating
true, the camera view rotates with the target.
- bool smoothing_enabled
true, the camera smoothly moves towards the target at smoothing_speed.
- float smoothing_speed
smoothing_enabled is
true.
- Vector2 zoom
Vector2(1, 1)zoom out and smaller values zoom in. For an example, useVector2(0.5, 0.5)for a 2× zoom-in, andVector2(4, 4)for a 4× zoom-out.Method Descriptions
- align ( ) Aligns the camera to the tracked node.
- clear_current ( )
Camera2Dfrom the ancestor Viewport‘s internal currently-assigned camera.
- force_update_scroll ( ) Forces the camera to update scroll immediately.
- Vector2 get_camera_position ( ) const
position(the tracked point the camera attempts to follow), relative to the origin. Note: The returned value is not the same as Node2D.position or Node2D.global_position, as it is affected by thedragproperties.
- Vector2 get_camera_screen_center ( ) const
Camera2D‘s screen-center, relative to the origin. Note: The realpositionof the camera may be different, see get_camera_position.
- float get_drag_margin ( Margin margin ) const drag_margin_bottom, drag_margin_top, drag_margin_left, and drag_margin_right.
- int get_limit ( Margin margin ) const limit_bottom, limit_top, limit_left, and limit_right.
- make_current ( ) Make this the current 2D camera for the scene (viewport and layer), in case there are many cameras in the scene.
- reset_smoothing ( )
Sets the camera’s position immediately to its current smoothing destination.
smoothing_enabled is
false.
- set_drag_margin ( Margin margin, float drag_margin ) drag_margin_bottom, drag_margin_top, drag_margin_left, and drag_margin_right.
- set_limit ( Margin margin, int limit ) limit_bottom, limit_top, limit_left, and limit_right.
