Struct Camera2D

Camera node for 2D scenes.

struct Camera2D ;

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

Properties

NameTypeDescription
anchorMode[get, set] Camera2D.AnchorModeThe Camera2D's anchor point. See anchormode constants.
current[get, set] boolIf 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.
customViewport[get, set] NodeThe custom Viewport node attached to the Camera2D. If null or not a Viewport, uses the default viewport instead.
dragMarginBottom[get, set] doubleBottom margin needed to drag the camera. A value of 1 makes the camera move only when reaching the edge of the screen.
dragMarginHEnabled[get, set] boolIf true, the camera only moves when reaching the horizontal drag margins. If false, the camera moves horizontally regardless of margins.
dragMarginLeft[get, set] doubleLeft margin needed to drag the camera. A value of 1 makes the camera move only when reaching the edge of the screen.
dragMarginRight[get, set] doubleRight margin needed to drag the camera. A value of 1 makes the camera move only when reaching the edge of the screen.
dragMarginTop[get, set] doubleTop margin needed to drag the camera. A value of 1 makes the camera move only when reaching the edge of the screen.
dragMarginVEnabled[get, set] boolIf true, the camera only moves when reaching the vertical drag margins. If false, the camera moves vertically regardless of margins.
editorDrawDragMargin[get, set] boolIf true, draws the camera's drag margin rectangle in the editor.
editorDrawLimits[get, set] boolIf true, draws the camera's limits rectangle in the editor.
editorDrawScreen[get, set] boolIf true, draws the camera's screen rectangle in the editor.
limitBottom[get, set] longBottom scroll limit in pixels. The camera stops moving when reaching this value.
limitLeft[get, set] longLeft scroll limit in pixels. The camera stops moving when reaching this value.
limitRight[get, set] longRight scroll limit in pixels. The camera stops moving when reaching this value.
limitSmoothed[get, set] boolIf true, the camera smoothly stops when reaches its limits.
limitTop[get, set] longTop scroll limit in pixels. The camera stops moving when reaching this value.
offset[get, set] Vector2The camera's offset, useful for looking around or camera shake animations.
offsetH[get, set] doubleThe horizontal offset of the camera, relative to the drag margins. Note: Offset H is used only to force offset relative to margins. It's not updated in any way if drag margins are enabled and can be used to set initial offset.
offsetV[get, set] doubleThe vertical offset of the camera, relative to the drag margins. Note: Used the same as offsetH.
processMode[get, set] Camera2D.Camera2DProcessModeThe camera's process callback. See camera2dprocessmode.
rotating[get, set] boolIf true, the camera rotates with the target.
smoothingEnabled[get, set] boolIf true, the camera smoothly moves towards the target at smoothingSpeed.
smoothingSpeed[get, set] doubleSpeed in pixels per second of the camera's smoothing effect when smoothingEnabled is true.
zoom[get, set] Vector2The 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 2× zoom-in, and Vector2(4, 4) for a 4× zoom-out.

Methods

NameDescription
_align Aligns the camera to the tracked node.
_makeCurrent
_setCurrent
_setOldSmoothing
_updateScroll
clearCurrent Removes any Camera2D from the ancestor Viewport's internal currently-assigned camera.
forceUpdateScroll Forces the camera to update scroll immediately.
getAnchorMode
getCameraPosition Returns the camera position.
getCameraScreenCenter Returns the location of the Camera2D's screen-center, relative to the origin.
getCustomViewport
getDragMargin Returns the specified margin. See also dragMarginBottom, dragMarginTop, dragMarginLeft, and dragMarginRight.
getFollowSmoothing
getHOffset
getLimit Returns the specified camera limit. See also limitBottom, limitTop, limitLeft, and limitRight.
getOffset
getProcessMode
getVOffset
getZoom
isCurrent
isFollowSmoothingEnabled
isHDragEnabled
isLimitDrawingEnabled
isLimitSmoothingEnabled
isMarginDrawingEnabled
isRotating
isScreenDrawingEnabled
isVDragEnabled
makeCurrent Make this the current 2D camera for the scene (viewport and layer), in case there are many cameras in the scene.
resetSmoothing Sets the camera's position immediately to its current smoothing destination. This has no effect if smoothing is disabled.
setAnchorMode
setCustomViewport
setDragMargin Sets the specified margin. See also dragMarginBottom, dragMarginTop, dragMarginLeft, and dragMarginRight.
setEnableFollowSmoothing
setFollowSmoothing
setHDragEnabled
setHOffset
setLimit Sets the specified camera limit. See also limitBottom, limitTop, limitLeft, and limitRight.
setLimitDrawingEnabled
setLimitSmoothingEnabled
setMarginDrawingEnabled
setOffset
setProcessMode
setRotating
setScreenDrawingEnabled
setVDragEnabled
setVOffset
setZoom

Enums

NameDescription
AnchorMode
Camera2DProcessMode
Constants