Skip to content
Lukas Sägesser edited this page Jun 22, 2015 · 12 revisions

Camera2D

####Inherits: Node2D ####Category: Core

Brief Description

Camera node for 2D scenes.

Member Functions

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 set_offset ( Vector2 offset )

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

Return the scroll offset.

  • void set_centered ( bool centered )

Set to true if the camera is at the center of the screen (default: true).

  • bool is_centered ( ) const

Return true if the camera is at the center of the screen (default: true).

  • void make_current ( )

Make this the current 2D camera for the scene (viewport and layer), in case there's many cameras in the scene.

  • bool is_current ( ) const

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

  • void set_limit ( int margin, int limit )

Set the scrolling limit in pixels

  • int get_limit ( int margin ) const

Return the scrolling limit in pixels

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

  • float get_drag_margin ( int margin ) const

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

Return the camera position.

  • void force_update_scroll ( )

Force the camera to update scroll immediately.

Clone this wiki locally