Camera2D¶
Inherits: Node2D < CanvasItem < Node < Object
Category: Core
Brief Description¶
Camera node for 2D scenes.
Member Functions¶
void | align ( ) |
void | clear_current ( ) |
void | force_update_scroll ( ) |
Vector2 | get_camera_position ( ) const |
Vector2 | get_camera_screen_center ( ) const |
void | make_current ( ) |
void | reset_smoothing ( ) |
Member Variables¶
- AnchorMode anchor_mode - The Camera2D’s anchor point. See
ANCHOR_MODE_*
constants. - bool current - If
true
the camera is the active camera for the current scene. Only one camera can be current, so setting a different cameracurrent
will disable this one. - Node 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 - 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 - If
true
the camera only moves when reaching the horizontal drag margins. Iffalse
the camera moves horizontally regardless of margins. Default value:true
. - float drag_margin_left - Left margin needed to drag the camera. A value of
1
makes the camera move only when reaching the edge of the screen. - float drag_margin_right - Right margin needed to drag the camera. A value of
1
makes the camera move only when reaching the edge of the screen. - float 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 - If
true
the camera only moves when reaching the vertical drag margins. Iffalse
the camera moves vertically regardless of margins. Default value:true
. - bool editor_draw_drag_margin - If
true
draws the camera’s drag margin rectangle in the editor. Default value:false
- bool editor_draw_limits - If
true
draws the camera’s limits rectangle in the editor. Default value:true
- bool editor_draw_screen - If
true
draws the camera’s screen rectangle in the editor. Default value:false
- 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 - If
true
the camera smoothly stops when reaches its limits. Default value:false
- 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. Default value:
0
- float offset_v - The vertical offset of the camera, relative to the drag margins. Default value:
0
- bool rotating - If
true
the camera rotates with the target. Default value:false
- bool smoothing_enabled - If
true
the camera smoothly moves towards the target at smoothing_speed. Default value:false
- float smoothing_speed - Speed in pixels per second of the camera’s smoothing effect when smoothing_enabled is
true
- Vector2 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, useVector2(0.5, 0.5)
for a 2x zoom in, andVector2(4, 4)
for a 4x zoom out.
Enums¶
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.
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.
Member Function Description¶
- 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
Return 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.