W3cubDocs

/Godot 3.1

Camera2D

Inherits: Node2D < CanvasItem < Node < Object

Category: Core

Brief Description

Camera node for 2D scenes.

Properties

AnchorMode anchor_mode
bool current
Node custom_viewport
float drag_margin_bottom
bool drag_margin_h_enabled
float drag_margin_left
float drag_margin_right
float drag_margin_top
bool drag_margin_v_enabled
bool editor_draw_drag_margin
bool editor_draw_limits
bool editor_draw_screen
int limit_bottom
int limit_left
int limit_right
bool limit_smoothed
int limit_top
Vector2 offset
float offset_h
float offset_v
Camera2DProcessMode process_mode
bool rotating
bool smoothing_enabled
float smoothing_speed
Vector2 zoom

Methods

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 ( )

Enumerations

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.

enum Camera2DProcessMode:

  • CAMERA2D_PROCESS_PHYSICS = 0
  • CAMERA2D_PROCESS_IDLE = 1

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.

Property Descriptions

AnchorMode anchor_mode

Setter set_anchor_mode(value)
Getter get_anchor_mode()

The Camera2D’s anchor point. See ANCHOR_MODE_* constants.

bool current

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.

Node custom_viewport

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.

float drag_margin_bottom

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.

bool drag_margin_h_enabled

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 value: true.

float drag_margin_left

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.

float drag_margin_right

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.

float drag_margin_top

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.

bool drag_margin_v_enabled

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 value: true.

bool editor_draw_drag_margin

Setter set_margin_drawing_enabled(value)
Getter is_margin_drawing_enabled()

If true, draws the camera’s drag margin rectangle in the editor. Default value: false

bool editor_draw_limits

Setter set_limit_drawing_enabled(value)
Getter is_limit_drawing_enabled()

If true, draws the camera’s limits rectangle in the editor. Default value: true

bool editor_draw_screen

Setter set_screen_drawing_enabled(value)
Getter is_screen_drawing_enabled()

If true, draws the camera’s screen rectangle in the editor. Default value: false

int limit_bottom

Setter set_limit(value)
Getter get_limit()

Bottom scroll limit in pixels. The camera stops moving when reaching this value.

int limit_left

Setter set_limit(value)
Getter get_limit()

Left scroll limit in pixels. The camera stops moving when reaching this value.

int limit_right

Setter set_limit(value)
Getter get_limit()

Right scroll limit in pixels. The camera stops moving when reaching this value.

bool limit_smoothed

Setter set_limit_smoothing_enabled(value)
Getter is_limit_smoothing_enabled()

If true, the camera smoothly stops when reaches its limits. Default value: false

int limit_top

Setter set_limit(value)
Getter get_limit()

Top scroll limit in pixels. The camera stops moving when reaching this value.

Vector2 offset

Setter set_offset(value)
Getter get_offset()

The camera’s offset, useful for looking around or camera shake animations.

float offset_h

Setter set_h_offset(value)
Getter get_h_offset()

The horizontal offset of the camera, relative to the drag margins. Default value: 0

float offset_v

Setter set_v_offset(value)
Getter get_v_offset()

The vertical offset of the camera, relative to the drag margins. Default value: 0

Camera2DProcessMode process_mode

Setter set_process_mode(value)
Getter get_process_mode()

bool rotating

Setter set_rotating(value)
Getter is_rotating()

If true, the camera rotates with the target. Default value: false

bool smoothing_enabled

Setter set_enable_follow_smoothing(value)
Getter is_follow_smoothing_enabled()

If true, the camera smoothly moves towards the target at smoothing_speed. Default value: false

float smoothing_speed

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

Vector2 zoom

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 2x zoom in, and Vector2(4, 4) for a 4x zoom out.

Method Descriptions

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

Returns 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.

© 2014–2019 Juan Linietsky, Ariel Manzur, Godot Engine contributors
Licensed under the MIT License.
http://docs.godotengine.org/en/3.1/classes/class_camera2d.html