Skip to content

class_camera2d

reduz edited this page Feb 23, 2014 · 11 revisions

Camera2D

Inherits: Node2D\n\n

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

Clone this wiki locally