Camera2D

Inherits: Node2D < CanvasItem < Node < Object

Category: Core

Brief Description

Camera node for 2D scenes.

Member Functions

void clear_current ( )
void force_update_scroll ( )
int get_anchor_mode ( ) const
Vector2 get_camera_pos ( ) const
Vector2 get_camera_screen_center ( ) const
float get_drag_margin ( int margin ) const
float get_follow_smoothing ( ) const
float get_h_offset ( ) const
int get_limit ( int margin ) const
Vector2 get_offset ( ) const
float get_v_offset ( ) const
Vector2 get_zoom ( ) const
bool is_current ( ) const
bool is_follow_smoothing_enabled ( ) const
bool is_h_drag_enabled ( ) const
bool is_rotating ( ) const
bool is_v_drag_enabled ( ) const
void make_current ( )
void set_anchor_mode ( int anchor_mode )
void set_drag_margin ( int margin, float drag_margin )
void set_enable_follow_smoothing ( bool follow_smoothing )
void set_follow_smoothing ( float follow_smoothing )
void set_h_drag_enabled ( bool enabled )
void set_h_offset ( float ofs )
void set_limit ( int margin, int limit )
void set_offset ( Vector2 offset )
void set_rotating ( bool rotating )
void set_v_drag_enabled ( bool enabled )
void set_v_offset ( float ofs )
void set_zoom ( Vector2 zoom )

Numeric Constants

  • ANCHOR_MODE_DRAG_CENTER = 1
  • ANCHOR_MODE_FIXED_TOP_LEFT = 0

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

Member Function Description

  • void clear_current ( )
  • void force_update_scroll ( )

Force the camera to update scroll immediately.

  • int get_anchor_mode ( ) const

Return the camera position.

  • Vector2 get_camera_screen_center ( ) const
  • float get_drag_margin ( int margin ) const

Return the margins needed to drag the camera (see set_drag_margin).

  • float get_follow_smoothing ( ) const
  • float get_h_offset ( ) const
  • int get_limit ( int margin ) const

Return the scrolling limit in pixels.

Return the scroll offset.

  • float get_v_offset ( ) const
  • bool is_current ( ) const

Return true of this is the current camera (see make_current).

  • bool is_follow_smoothing_enabled ( ) const
  • bool is_h_drag_enabled ( ) const
  • bool is_rotating ( ) const
  • bool is_v_drag_enabled ( ) const
  • 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 set_anchor_mode ( int anchor_mode )
  • void set_drag_margin ( int margin, float drag_margin )

Set the margins needed to drag the camera (relative to the screen size). Margin uses the MARGIN_* enum. Drag margins of 0,0,0,0 will keep the camera at the center of the screen, while drag margins of 1,1,1,1 will only move when the camera is at the edges.

  • void set_enable_follow_smoothing ( bool follow_smoothing )
  • void set_follow_smoothing ( float follow_smoothing )
  • void set_h_drag_enabled ( bool enabled )
  • void set_h_offset ( float ofs )
  • void set_limit ( int margin, int limit )

Set the scrolling limit in pixels.

  • void set_offset ( Vector2 offset )

Set the scroll offset. Useful for looking around or camera shake animations.

  • void set_rotating ( bool rotating )
  • void set_v_drag_enabled ( bool enabled )
  • void set_v_offset ( float ofs )