Inherits: Node2D < CanvasItem < Node < Object
Camera node for 2D scenes.
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 that more functionality is desired to change how the camera works. To make your own custom camera node, inherit from 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).
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 get_camera_screen_center to get the real position.
AnchorMode | anchor_mode | 1 |
bool | current | false |
Node | custom_viewport | |
float | drag_margin_bottom | 0.2 |
bool | drag_margin_h_enabled | false |
float | drag_margin_left | 0.2 |
float | drag_margin_right | 0.2 |
float | drag_margin_top | 0.2 |
bool | drag_margin_v_enabled | false |
bool | editor_draw_drag_margin | false |
bool | editor_draw_limits | false |
bool | editor_draw_screen | true |
int | limit_bottom | 10000000 |
int | limit_left | -10000000 |
int | limit_right | 10000000 |
bool | limit_smoothed | false |
int | limit_top | -10000000 |
Vector2 | offset | Vector2( 0, 0 ) |
float | offset_h | 0.0 |
float | offset_v | 0.0 |
Camera2DProcessMode | process_mode | 1 |
bool | rotating | false |
bool | smoothing_enabled | false |
float | smoothing_speed | 5.0 |
Vector2 | zoom | Vector2( 1, 1 ) |
void | align ( ) |
void | clear_current ( ) |
void | force_update_scroll ( ) |
Vector2 | get_camera_position ( ) const |
Vector2 | get_camera_screen_center ( ) const |
float | get_drag_margin ( Margin margin ) const |
int | get_limit ( Margin margin ) const |
void | make_current ( ) |
void | reset_smoothing ( ) |
void | set_drag_margin ( Margin margin, float drag_margin ) |
void | set_limit ( Margin margin, int limit ) |
enum AnchorMode:
enum Camera2DProcessMode:
_physics_process
callback._process
callback.Default | 1 |
Setter | set_anchor_mode(value) |
Getter | get_anchor_mode() |
The Camera2D's anchor point. See AnchorMode constants.
Default | false |
Getter | 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.
Setter | set_custom_viewport(value) |
Getter | get_custom_viewport() |
The custom Viewport node attached to the Camera2D
. If null
or not a Viewport, uses the default viewport instead.
Default | 0.2 |
Setter | set_drag_margin(value) |
Getter | get_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.
Default | false |
Setter | set_h_drag_enabled(value) |
Getter | 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.
Default | 0.2 |
Setter | set_drag_margin(value) |
Getter | get_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.
Default | 0.2 |
Setter | set_drag_margin(value) |
Getter | get_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.
Default | 0.2 |
Setter | set_drag_margin(value) |
Getter | get_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.
Default | false |
Setter | set_v_drag_enabled(value) |
Getter | 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.
Default | false |
Setter | set_margin_drawing_enabled(value) |
Getter | is_margin_drawing_enabled() |
If true
, draws the camera's drag margin rectangle in the editor.
Default | false |
Setter | set_limit_drawing_enabled(value) |
Getter | is_limit_drawing_enabled() |
If true
, draws the camera's limits rectangle in the editor.
Default | true |
Setter | set_screen_drawing_enabled(value) |
Getter | is_screen_drawing_enabled() |
If true
, draws the camera's screen rectangle in the editor.
Default | 10000000 |
Setter | set_limit(value) |
Getter | get_limit() |
Bottom scroll limit in pixels. The camera stops moving when reaching this value.
Default | -10000000 |
Setter | set_limit(value) |
Getter | get_limit() |
Left scroll limit in pixels. The camera stops moving when reaching this value.
Default | 10000000 |
Setter | set_limit(value) |
Getter | get_limit() |
Right scroll limit in pixels. The camera stops moving when reaching this value.
Default | false |
Setter | set_limit_smoothing_enabled(value) |
Getter | is_limit_smoothing_enabled() |
If true
, the camera smoothly stops when reaches its limits.
Default | -10000000 |
Setter | set_limit(value) |
Getter | get_limit() |
Top scroll limit in pixels. The camera stops moving when reaching this value.
Default | Vector2( 0, 0 ) |
Setter | set_offset(value) |
Getter | get_offset() |
The camera's offset, useful for looking around or camera shake animations.
Default | 0.0 |
Setter | set_h_offset(value) |
Getter | 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.
Default | 0.0 |
Setter | set_v_offset(value) |
Getter | get_v_offset() |
The vertical offset of the camera, relative to the drag margins.
Note: Used the same as offset_h.
Default | 1 |
Setter | set_process_mode(value) |
Getter | get_process_mode() |
The camera's process callback. See Camera2DProcessMode.
Default | false |
Setter | set_rotating(value) |
Getter | is_rotating() |
If true
, the camera rotates with the target.
Default | false |
Setter | set_enable_follow_smoothing(value) |
Getter | is_follow_smoothing_enabled() |
If true
, the camera smoothly moves towards the target at smoothing_speed.
Default | 5.0 |
Setter | set_follow_smoothing(value) |
Getter | get_follow_smoothing() |
Speed in pixels per second of the camera's smoothing effect when smoothing_enabled is true
.
Default | Vector2( 1, 1 ) |
Setter | set_zoom(value) |
Getter | 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.
Aligns the camera to the tracked node.
Removes any Camera2D
from the ancestor Viewport's internal currently-assigned camera.
Forces the camera to update scroll immediately.
Returns the camera position.
Returns the location of the Camera2D
's screen-center, relative to the origin.
Returns the specified margin. See also drag_margin_bottom, drag_margin_top, drag_margin_left, and drag_margin_right.
Returns the specified camera limit. See also limit_bottom, limit_top, limit_left, and limit_right.
Make this the current 2D camera for the scene (viewport and layer), in case there are many cameras in the scene.
Sets the camera's position immediately to its current smoothing destination.
This has no effect if smoothing is disabled.
Sets the specified margin. See also drag_margin_bottom, drag_margin_top, drag_margin_left, and drag_margin_right.
Sets the specified camera limit. See also limit_bottom, limit_top, limit_left, and limit_right.
© 2014–2020 Juan Linietsky, Ariel Manzur, Godot Engine contributors
Licensed under the MIT License.
https://docs.godotengine.org/en/3.2/classes/class_camera2d.html