Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Camera2D¶
Inherits: Node2D < CanvasItem < Node < Object
Camera node for 2D scenes.
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.
Cameras register themselves in the nearest Viewport node (when ascending the tree). Only one camera can be active per viewport. If no viewport is available ascending the tree, the camera will register in the global viewport.
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 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_screen_center_position to get the real position.
Tutorials¶
Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Methods¶
void |
align ( ) |
void |
|
get_drag_margin ( Side margin ) const |
|
get_screen_center_position ( ) const |
|
get_target_position ( ) const |
|
is_current ( ) const |
|
void |
make_current ( ) |
void |
reset_smoothing ( ) |
void |
set_drag_margin ( Side margin, float drag_margin ) |
void |
Enumerations¶
enum AnchorMode:
AnchorMode ANCHOR_MODE_FIXED_TOP_LEFT = 0
The camera's position is fixed so that the top-left corner is always at the origin.
AnchorMode ANCHOR_MODE_DRAG_CENTER = 1
The camera's position takes into account vertical/horizontal offsets and the screen size.
enum Camera2DProcessCallback:
Camera2DProcessCallback CAMERA2D_PROCESS_PHYSICS = 0
The camera updates during physics frames (see Node.NOTIFICATION_INTERNAL_PHYSICS_PROCESS).
Camera2DProcessCallback CAMERA2D_PROCESS_IDLE = 1
The camera updates during process frames (see Node.NOTIFICATION_INTERNAL_PROCESS).
Property Descriptions¶
AnchorMode anchor_mode = 1
void set_anchor_mode ( AnchorMode value )
AnchorMode get_anchor_mode ( )
The Camera2D's anchor point. See AnchorMode constants.
Node custom_viewport
The custom Viewport node attached to the Camera2D. If null
or not a Viewport, uses the default viewport instead.
float drag_bottom_margin = 0.2
Bottom margin needed to drag the camera. A value of 1
makes the camera move only when reaching the bottom edge of the screen.
bool drag_horizontal_enabled = false
If true
, the camera only moves when reaching the horizontal (left and right) drag margins. If false
, the camera moves horizontally regardless of margins.
float drag_horizontal_offset = 0.0
The relative horizontal drag offset of the camera between the right (-1
) and left (1
) drag margins.
Note: Used to set the initial horizontal drag offset; determine the current offset; or force the current offset. It's not automatically updated when drag_horizontal_enabled is true
or the drag margins are changed.
float drag_left_margin = 0.2
Left margin needed to drag the camera. A value of 1
makes the camera move only when reaching the left edge of the screen.
float drag_right_margin = 0.2
Right margin needed to drag the camera. A value of 1
makes the camera move only when reaching the right edge of the screen.
float drag_top_margin = 0.2
Top margin needed to drag the camera. A value of 1
makes the camera move only when reaching the top edge of the screen.
bool drag_vertical_enabled = false
If true
, the camera only moves when reaching the vertical (top and bottom) drag margins. If false
, the camera moves vertically regardless of the drag margins.
float drag_vertical_offset = 0.0
The relative vertical drag offset of the camera between the bottom (-1
) and top (1
) drag margins.
Note: Used to set the initial vertical drag offset; determine the current offset; or force the current offset. It's not automatically updated when drag_vertical_enabled is true
or the drag margins are changed.
bool editor_draw_drag_margin = false
If true
, draws the camera's drag margin rectangle in the editor.