Documentation
¶
Overview ¶
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.
Cameras register themselves in the nearest Viewport node (when ascending the tree). Only one camera can be active per viewport. If no viewport is available ascending the tree, the camera will register in the global viewport.
This node is intended to be a simple helper to get things going quickly, but more functionality may be desired to change how the camera works. To make your own custom camera node, inherit it from Node2D and change the transform of the canvas by setting Viewport.CanvasTransform in Viewport (you can obtain the current Viewport by using Node.GetViewport).
Note that the Camera2D node's Node2D.GlobalPosition doesn't represent the actual position of the screen, which may differ due to applied smoothing or limits. You can use GetScreenCenterPosition to get the real position. Same for the node's Node2D.GlobalRotation which may be different due to applied rotation smoothing. You can use GetScreenRotation to get the current rotation of the screen.
Index ¶
- type Advanced
- type AnchorMode
- type Any
- type Camera2DProcessCallback
- type Extension
- type ID
- type Instance
- func (self Instance) Align()
- func (self Instance) AnchorMode() AnchorMode
- func (self Instance) AsCamera2D() Instance
- func (self Instance) AsCanvasItem() CanvasItem.Instance
- func (self Instance) AsNode() Node.Instance
- func (self Instance) AsNode2D() Node2D.Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) CustomViewport() Node.Instance
- func (self Instance) DragBottomMargin() Float.X
- func (self Instance) DragHorizontalEnabled() bool
- func (self Instance) DragHorizontalOffset() Float.X
- func (self Instance) DragLeftMargin() Float.X
- func (self Instance) DragRightMargin() Float.X
- func (self Instance) DragTopMargin() Float.X
- func (self Instance) DragVerticalEnabled() bool
- func (self Instance) DragVerticalOffset() Float.X
- func (self Instance) EditorDrawDragMargin() bool
- func (self Instance) EditorDrawLimits() bool
- func (self Instance) EditorDrawScreen() bool
- func (self Instance) Enabled() bool
- func (self Instance) ForceUpdateScroll()
- func (self Instance) GetScreenCenterPosition() Vector2.XY
- func (self Instance) GetScreenRotation() Float.X
- func (self Instance) GetTargetPosition() Vector2.XY
- func (self Instance) ID() ID
- func (self Instance) IgnoreRotation() bool
- func (self Instance) IsCurrent() bool
- func (self Instance) LimitBottom() int
- func (self Instance) LimitEnabled() bool
- func (self Instance) LimitLeft() int
- func (self Instance) LimitRight() int
- func (self Instance) LimitSmoothed() bool
- func (self Instance) LimitTop() int
- func (self Instance) MakeCurrent()
- func (self Instance) Offset() Vector2.XY
- func (self Instance) PositionSmoothingEnabled() bool
- func (self Instance) PositionSmoothingSpeed() Float.X
- func (self Instance) ProcessCallback() Camera2DProcessCallback
- func (self Instance) ResetSmoothing()
- func (self Instance) RotationSmoothingEnabled() bool
- func (self Instance) RotationSmoothingSpeed() Float.X
- func (self Instance) SetAnchorMode(value AnchorMode)
- func (self Instance) SetCustomViewport(value Node.Instance)
- func (self Instance) SetDragBottomMargin(value Float.X)
- func (self Instance) SetDragHorizontalEnabled(value bool)
- func (self Instance) SetDragHorizontalOffset(value Float.X)
- func (self Instance) SetDragLeftMargin(value Float.X)
- func (self Instance) SetDragRightMargin(value Float.X)
- func (self Instance) SetDragTopMargin(value Float.X)
- func (self Instance) SetDragVerticalEnabled(value bool)
- func (self Instance) SetDragVerticalOffset(value Float.X)
- func (self Instance) SetEditorDrawDragMargin(value bool)
- func (self Instance) SetEditorDrawLimits(value bool)
- func (self Instance) SetEditorDrawScreen(value bool)
- func (self Instance) SetEnabled(value bool)
- func (self Instance) SetIgnoreRotation(value bool)
- func (self Instance) SetLimitBottom(value int)
- func (self Instance) SetLimitEnabled(value bool)
- func (self Instance) SetLimitLeft(value int)
- func (self Instance) SetLimitRight(value int)
- func (self Instance) SetLimitSmoothed(value bool)
- func (self Instance) SetLimitTop(value int)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetOffset(value Vector2.XY)
- func (self Instance) SetPositionSmoothingEnabled(value bool)
- func (self Instance) SetPositionSmoothingSpeed(value Float.X)
- func (self Instance) SetProcessCallback(value Camera2DProcessCallback)
- func (self Instance) SetRotationSmoothingEnabled(value bool)
- func (self Instance) SetRotationSmoothingSpeed(value Float.X)
- func (self Instance) SetZoom(value Vector2.XY)
- func (self Instance) Virtual(name string) reflect.Value
- func (self Instance) Zoom() Vector2.XY
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type AnchorMode ¶
type AnchorMode int //gd:Camera2D.AnchorMode
const ( // The camera's position is fixed so that the top-left corner is always at the origin. AnchorModeFixedTopLeft AnchorMode = 0 // The camera's position takes into account vertical/horizontal offsets and the screen size. AnchorModeDragCenter AnchorMode = 1 )
type Camera2DProcessCallback ¶
type Camera2DProcessCallback int //gd:Camera2D.Camera2DProcessCallback
const ( // The camera updates during physics frames (see [Node.NotificationInternalPhysicsProcess]). Camera2dProcessPhysics Camera2DProcessCallback = 0 // The camera updates during process frames (see [Node.NotificationInternalProcess]). Camera2dProcessIdle Camera2DProcessCallback = 1 )
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsCamera2D ¶
func (*Extension[T]) AsCanvasItem ¶
func (self *Extension[T]) AsCanvasItem() CanvasItem.Instance
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AnchorMode ¶
func (self Instance) AnchorMode() AnchorMode
The Camera2D's anchor point.
func (Instance) AsCamera2D ¶
func (Instance) AsCanvasItem ¶
func (self Instance) AsCanvasItem() CanvasItem.Instance
func (Instance) CustomViewport ¶
The custom Viewport node attached to the Camera2D. If null or not a Viewport, uses the default viewport instead.
func (Instance) DragBottomMargin ¶
Bottom margin needed to drag the camera. A value of 1 makes the camera move only when reaching the bottom edge of the screen.
func (Instance) DragHorizontalEnabled ¶
If true, the camera only moves when reaching the horizontal (left and right) drag margins. If false, the camera moves horizontally regardless of margins.
func (Instance) DragHorizontalOffset ¶
The relative horizontal drag offset of the camera between the right (-1) and left (1) drag margins.
Note: Used to set the initial horizontal drag offset; determine the current offset; or force the current offset. It's not automatically updated when DragHorizontalEnabled is true or the drag margins are changed.
func (Instance) DragLeftMargin ¶
Left margin needed to drag the camera. A value of 1 makes the camera move only when reaching the left edge of the screen.
func (Instance) DragRightMargin ¶
Right margin needed to drag the camera. A value of 1 makes the camera move only when reaching the right edge of the screen.
func (Instance) DragTopMargin ¶
Top margin needed to drag the camera. A value of 1 makes the camera move only when reaching the top edge of the screen.
func (Instance) DragVerticalEnabled ¶
If true, the camera only moves when reaching the vertical (top and bottom) drag margins. If false, the camera moves vertically regardless of the drag margins.
func (Instance) DragVerticalOffset ¶
The relative vertical drag offset of the camera between the bottom (-1) and top (1) drag margins.
Note: Used to set the initial vertical drag offset; determine the current offset; or force the current offset. It's not automatically updated when DragVerticalEnabled is true or the drag margins are changed.
func (Instance) EditorDrawDragMargin ¶
If true, draws the camera's drag margin rectangle in the editor.
func (Instance) EditorDrawLimits ¶
If true, draws the camera's limits rectangle in the editor.
func (Instance) EditorDrawScreen ¶
If true, draws the camera's screen rectangle in the editor.
func (Instance) Enabled ¶
Controls whether the camera can be active or not. If true, the Camera2D will become the main camera when it enters the scene tree and there is no active camera currently (see Viewport.GetCamera2d).
When the camera is currently active and Enabled is set to false, the next enabled Camera2D in the scene tree will become active.
func (Instance) ForceUpdateScroll ¶
func (self Instance) ForceUpdateScroll()
Forces the camera to update scroll immediately.
func (Instance) GetScreenCenterPosition ¶
Returns the center of the screen from this camera's point of view, in global coordinates.
Note: The exact targeted position of the camera may be different. See GetTargetPosition.
func (Instance) GetScreenRotation ¶
Returns the current screen rotation from this camera's point of view.
Note: The screen rotation can be different from Node2D.GlobalRotation if the camera is rotating smoothly due to RotationSmoothingEnabled.
func (Instance) GetTargetPosition ¶
Returns this camera's target position, in global coordinates.
Note: The returned value is not the same as Node2D.GlobalPosition, as it is affected by the drag properties. It is also not the same as the current position if PositionSmoothingEnabled is true (see GetScreenCenterPosition).
func (Instance) IgnoreRotation ¶
If true, the camera's rendered view is not affected by its Node2D.Rotation and Node2D.GlobalRotation.
func (Instance) IsCurrent ¶
Returns true if this Camera2D is the active camera (see Viewport.GetCamera2d).
func (Instance) LimitBottom ¶
Bottom scroll limit in pixels. The camera stops moving when reaching this value, but Offset can push the view past the limit.
func (Instance) LimitEnabled ¶
If true, the limits will be enabled. Disabling this will allow the camera to focus anywhere, when the four limit_* properties will not work.
func (Instance) LimitLeft ¶
Left scroll limit in pixels. The camera stops moving when reaching this value, but Offset can push the view past the limit.
func (Instance) LimitRight ¶
Right scroll limit in pixels. The camera stops moving when reaching this value, but Offset can push the view past the limit.
func (Instance) LimitSmoothed ¶
If true, the camera smoothly stops when reaches its limits.
This property has no effect if PositionSmoothingEnabled is false.
Note: To immediately update the camera's position to be within limits without smoothing, even with this setting enabled, invoke ResetSmoothing.
func (Instance) LimitTop ¶
Top scroll limit in pixels. The camera stops moving when reaching this value, but Offset can push the view past the limit.
func (Instance) MakeCurrent ¶
func (self Instance) MakeCurrent()
Forces this Camera2D to become the current active one. Enabled must be true.
func (Instance) Offset ¶
The camera's relative offset. Useful for looking around or camera shake animations. The offsetted camera can go past the limits defined in LimitTop, LimitBottom, LimitLeft and LimitRight.
func (Instance) PositionSmoothingEnabled ¶
If true, the camera's view smoothly moves towards its target position at PositionSmoothingSpeed.
func (Instance) PositionSmoothingSpeed ¶
Speed in pixels per second of the camera's smoothing effect when PositionSmoothingEnabled is true.
func (Instance) ProcessCallback ¶
func (self Instance) ProcessCallback() Camera2DProcessCallback
The camera's process callback.
func (Instance) ResetSmoothing ¶
func (self Instance) ResetSmoothing()
Sets the camera's position immediately to its current smoothing destination.
This method has no effect if PositionSmoothingEnabled is false.
func (Instance) RotationSmoothingEnabled ¶
If true, the camera's view smoothly rotates, via asymptotic smoothing, to align with its target rotation at RotationSmoothingSpeed.
Note: This property has no effect if IgnoreRotation is true.
func (Instance) RotationSmoothingSpeed ¶
The angular, asymptotic speed of the camera's rotation smoothing effect when RotationSmoothingEnabled is true.
func (Instance) SetAnchorMode ¶
func (self Instance) SetAnchorMode(value AnchorMode)
SetAnchorMode sets the property returned by [GetAnchorMode].
func (Instance) SetCustomViewport ¶
SetCustomViewport sets the property returned by [GetCustomViewport].
func (Instance) SetDragBottomMargin ¶
SetDragBottomMargin sets the property returned by [GetDragMargin].
func (Instance) SetDragHorizontalEnabled ¶
SetDragHorizontalEnabled sets the property returned by [IsDragHorizontalEnabled].
func (Instance) SetDragHorizontalOffset ¶
SetDragHorizontalOffset sets the property returned by [GetDragHorizontalOffset].
func (Instance) SetDragLeftMargin ¶
SetDragLeftMargin sets the property returned by [GetDragMargin].
func (Instance) SetDragRightMargin ¶
SetDragRightMargin sets the property returned by [GetDragMargin].
func (Instance) SetDragTopMargin ¶
SetDragTopMargin sets the property returned by [GetDragMargin].
func (Instance) SetDragVerticalEnabled ¶
SetDragVerticalEnabled sets the property returned by [IsDragVerticalEnabled].
func (Instance) SetDragVerticalOffset ¶
SetDragVerticalOffset sets the property returned by [GetDragVerticalOffset].
func (Instance) SetEditorDrawDragMargin ¶
SetEditorDrawDragMargin sets the property returned by [IsMarginDrawingEnabled].
func (Instance) SetEditorDrawLimits ¶
SetEditorDrawLimits sets the property returned by [IsLimitDrawingEnabled].
func (Instance) SetEditorDrawScreen ¶
SetEditorDrawScreen sets the property returned by [IsScreenDrawingEnabled].
func (Instance) SetEnabled ¶
SetEnabled sets the property returned by [IsEnabled].
func (Instance) SetIgnoreRotation ¶
SetIgnoreRotation sets the property returned by [IsIgnoringRotation].
func (Instance) SetLimitBottom ¶
SetLimitBottom sets the property returned by [GetLimit].
func (Instance) SetLimitEnabled ¶
SetLimitEnabled sets the property returned by [IsLimitEnabled].
func (Instance) SetLimitLeft ¶
SetLimitLeft sets the property returned by [GetLimit].
func (Instance) SetLimitRight ¶
SetLimitRight sets the property returned by [GetLimit].
func (Instance) SetLimitSmoothed ¶
SetLimitSmoothed sets the property returned by [IsLimitSmoothingEnabled].
func (Instance) SetLimitTop ¶
SetLimitTop sets the property returned by [GetLimit].
func (Instance) SetPositionSmoothingEnabled ¶
SetPositionSmoothingEnabled sets the property returned by [IsPositionSmoothingEnabled].
func (Instance) SetPositionSmoothingSpeed ¶
SetPositionSmoothingSpeed sets the property returned by [GetPositionSmoothingSpeed].
func (Instance) SetProcessCallback ¶
func (self Instance) SetProcessCallback(value Camera2DProcessCallback)
SetProcessCallback sets the property returned by [GetProcessCallback].
func (Instance) SetRotationSmoothingEnabled ¶
SetRotationSmoothingEnabled sets the property returned by [IsRotationSmoothingEnabled].
func (Instance) SetRotationSmoothingSpeed ¶
SetRotationSmoothingSpeed sets the property returned by [GetRotationSmoothingSpeed].
func (Instance) Zoom ¶
The camera's zoom. Higher values are more zoomed in. For example, a zoom of Vector2(2.0, 2.0) will be twice as zoomed in on each axis (the view covers an area four times smaller). In contrast, a zoom of Vector2(0.5, 0.5) will be twice as zoomed out on each axis (the view covers an area four times larger). The X and Y components should generally always be set to the same value, unless you wish to stretch the camera view.
Note: FontFile.Oversampling does not take Camera2D zoom into account. This means that zooming in/out will cause bitmap fonts and rasterized (non-MSDF) dynamic fonts to appear blurry or pixelated unless the font is part of a CanvasLayer that makes it ignore camera zoom. To ensure text remains crisp regardless of zoom, you can enable MSDF font rendering by enabling ProjectSettings "gui/theme/default_font_multichannel_signed_distance_field" (applies to the default project font only), or enabling Multichannel Signed Distance Field in the import options of a DynamicFont for custom fonts. On system fonts, SystemFont.MultichannelSignedDistanceField can be enabled in the inspector.