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
Nodo de cámara para escenas 2D.
Descripción¶
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, 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_camera_screen_center to get the real position.
Tutoriales¶
Propiedades¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Métodos¶
void |
align ( ) |
void |
clear_current ( ) |
void |
|
get_camera_position ( ) const |
|
get_camera_screen_center ( ) const |
|
get_drag_margin ( Margin margin ) const |
|
void |
make_current ( ) |
void |
reset_smoothing ( ) |
void |
set_drag_margin ( Margin margin, float drag_margin ) |
void |
Enumeraciones¶
enum AnchorMode:
ANCHOR_MODE_FIXED_TOP_LEFT = 0 --- La posición de la cámara está fijada de tal manera que la esquina superior izquierda está siempre en el origen.
ANCHOR_MODE_DRAG_CENTER = 1 --- La posición de la cámara tiene en cuenta los desplazamientos verticales/horizontales y el tamaño de la pantalla.
enum Camera2DProcessMode:
CAMERA2D_PROCESS_PHYSICS = 0 --- La cámara se actualiza con la llamada
_physics_process
.CAMERA2D_PROCESS_IDLE = 1 --- La cámara se actualiza con la llamada de
_process
.
Descripciones de Propiedades¶
AnchorMode anchor_mode
Default |
|
Setter |
set_anchor_mode(value) |
Getter |
get_anchor_mode() |
El punto de anclaje de Camera2D. Ver las constantes de AnchorMode.
bool current
Default |
|
Getter |
is_current() |
Si true
, la cámara es la cámara activa para la escena actual. Sólo una cámara puede ser actual, por lo que configurar una cámara diferente current
deshabilitará ésta.
Node custom_viewport
Setter |
set_custom_viewport(value) |
Getter |
get_custom_viewport() |
El nodo personalizado de Viewport unido a Camera2D
. Si null
o no es un Viewport, usa el viewport por defecto en su lugar.
float drag_margin_bottom
Default |
|
Setter |
set_drag_margin(value) |
Getter |
get_drag_margin() |
El margen inferior se necesita para arrastrar la cámara. Un valor de 1
hace que la cámara se mueva sólo cuando llega al borde de la pantalla.
bool drag_margin_h_enabled
Default |
|
Setter |
set_h_drag_enabled(value) |
Getter |
is_h_drag_enabled() |
Si true
, la cámara sólo se mueve cuando alcanza los márgenes de arrastre horizontal. Si false
, la cámara se mueve horizontalmente independientemente de los márgenes.
float drag_margin_left
Default |
|
Setter |
set_drag_margin(value) |
Getter |
get_drag_margin() |
El margen izquierdo se necesita para arrastrar la cámara. Un valor de 1
hace que la cámara se mueva sólo cuando llega al borde de la pantalla.
float drag_margin_right
Default |
|
Setter |
set_drag_margin(value) |
Getter |
get_drag_margin() |
Se necesita un margen derecho para arrastrar la cámara. Un valor de 1
hace que la cámara se mueva sólo cuando llega al borde de la pantalla.
float drag_margin_top
Default |
|
Setter |
set_drag_margin(value) |
Getter |
get_drag_margin() |
Se necesita un margen superior para arrastrar la cámara. Un valor de 1
hace que la cámara se mueva sólo cuando llega al borde de la pantalla.
bool drag_margin_v_enabled
Default |
|
Setter |
set_v_drag_enabled(value) |
Getter |
is_v_drag_enabled() |
Si true
, la cámara sólo se mueve cuando alcanza los márgenes de arrastre vertical. Si false
, la cámara se mueve verticalmente sin importar los márgenes.
bool editor_draw_drag_margin
Default |
|
Setter |
set_margin_drawing_enabled(value) |
Getter |
is_margin_drawing_enabled() |
Si true
, dibuja el rectángulo de margen de arrastre de la cámara en el editor.
bool editor_draw_limits
Default |
|
Setter |
set_limit_drawing_enabled(value) |
Getter |
is_limit_drawing_enabled() |
Si true
, dibuja el rectángulo de límites de la cámara en el editor.
bool editor_draw_screen
Default |
|
Setter |
set_screen_drawing_enabled(value) |
Getter |
is_screen_drawing_enabled() |
Si true
, dibuja el rectángulo de la pantalla de la cámara en el editor.
int limit_bottom
Default |
|
Setter |
set_limit(value) |
Getter |
get_limit() |
Límite inferior de desplazamiento en píxeles. La cámara deja de moverse cuando alcanza este valor.
int limit_left
Default |
|
Setter |
set_limit(value) |
Getter |
get_limit() |
Límite de scroll izquierdo en píxeles. La cámara deja de moverse cuando alcanza este valor.
int limit_right
Default |
|
Setter |
set_limit(value) |
Getter |
get_limit() |
Límite de scroll derecho en píxeles. La cámara deja de moverse cuando alcanza este valor.
bool limit_smoothed
Default |
|
Setter |
set_limit_smoothing_enabled(value) |
Getter |
is_limit_smoothing_enabled() |
If true
, the camera smoothly stops when reaches its limits.
This property has no effect if smoothing_enabled is false
.
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
Default |
|
Setter |
set_limit(value) |
Getter |
get_limit() |
Límite superior de scroll en píxeles. La cámara deja de moverse cuando alcanza este valor.
Vector2 offset
Default |
|
Setter |
set_offset(value) |
Getter |
get_offset() |
El desplazamiento de la camara, útil para mirar alrededor o para las animaciones de agitación de la camara.
float offset_h
Default |
|
Setter |
set_h_offset(value) |
Getter |
get_h_offset() |
El desplazamiento horizontal de la cámara, relativo a los márgenes de arrastre.
Nota: El desplazamiento H se utiliza sólo para forzar el desplazamiento relativo a los márgenes. No se actualiza de ninguna manera si los márgenes de arrastre están activados y puede utilizarse para establecer el desplazamiento inicial.
float offset_v
Default |
|
Setter |
set_v_offset(value) |
Getter |
get_v_offset() |
El desplazamiento vertical de la cámara, relativo a los márgenes de arrastre.
Nota: Se utiliza igual que offset_h.
Camera2DProcessMode process_mode
Default |
|
Setter |
set_process_mode(value) |
Getter |
get_process_mode() |
La llamada al proceso de la cámara. Ver Camera2DProcessMode.
bool rotating
Default |
|
Setter |
set_rotating(value) |
Getter |
is_rotating() |
If true
, the camera view rotates with the target.
bool smoothing_enabled
Default |
|
Setter |
set_enable_follow_smoothing(value) |
Getter |
is_follow_smoothing_enabled() |
Si true
, la cámara se mueve suavemente hacia el objetivo a smoothing_speed.
float smoothing_speed
Default |
|
Setter |
set_follow_smoothing(value) |
Getter |
get_follow_smoothing() |
Velocidad en píxeles por segundo del efecto de suavizado de la cámara cuando smoothing_enabled es true
.
Vector2 zoom
Default |
|
Setter |
set_zoom(value) |
Getter |
get_zoom() |
El zoom de la cámara en relación con el punto de vista. Los valores mayores que Vector2(1, 1)
se alejan y los valores menores se acercan. Para un ejemplo, use Vector2(0,5, 0,5)
para un zoom invertido de 2×, y Vector2(4, 4)
para un zoom de 4×.
Descripciones de Métodos¶
void align ( )
Alinea la cámara con el nodo de seguimiento.
void clear_current ( )
Quita cualquier Camera2D
de la cámara interna del antepasado Viewport actualmente asignada.
void force_update_scroll ( )
Obliga a la cámara a actualizar el scroll inmediatamente.
Vector2 get_camera_position ( ) const
Returns the camera's 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 the drag
properties.
Vector2 get_camera_screen_center ( ) const
Returns the location of the Camera2D
's screen-center, relative to the origin.
Note: The real position
of the camera may be different, see get_camera_position.
Devuelve el margen especificado. Véase también drag_margin_bottom, drag_margin_top, drag_margin_left, y drag_margin_right.
Devuelve el límite de cámara especificado. Consulte también limit_bottom, limit_top, limit_left y limit_right.
void make_current ( )
Haz que esta sea la cámara 2D actual para la escena (viewport y layer), en caso de que haya muchas cámaras en la escena.
void reset_smoothing ( )
Sets the camera's position immediately to its current smoothing destination.
This method has no effect if smoothing_enabled is false
.
Establece el margen especificado. Véase también drag_margin_bottom, drag_margin_top, drag_margin_left, y drag_margin_right.
Establece el límite de cámara especificado. Consulte también limit_bottom, limit_top, limit_left y limit_right.