Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
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