Parallax2D
A node used to create a parallax scrolling background.
A node used to create a parallax scrolling background.
A Parallax2D is used to create a parallax effect. It can move at a different speed relative to the camera movement using Parallax2D.ScrollScale. This creates an illusion of depth in a 2D game. If manual scrolling is desired, the Camera2D position can be ignored with Parallax2D.IgnoreCameraScroll.
Note: Any changes to this node's position made after it enters the scene tree will be overridden if Parallax2D.IgnoreCameraScroll is false or Parallax2D.ScreenOffset is modified.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
Parallax2DConstructor
public Parallax2D();Properties10
AutoscrollProperty
public Vector2 Autoscroll { get; set; }Velocity at which the offset scrolls automatically, in pixels per second.
FollowViewportProperty
public bool FollowViewport { get; set; }If true, this Parallax2D is offset by the current camera's position. If the Parallax2D is in a CanvasLayer separate from the current camera, it may be desired to match the value with CanvasLayer.FollowViewportEnabled.
IgnoreCameraScrollProperty
public bool IgnoreCameraScroll { get; set; }If true, Parallax2D's position is not affected by the position of the camera.
LimitBeginProperty
public Vector2 LimitBegin { get; set; }Top-left limits for scrolling to begin. If the camera is outside of this limit, the Parallax2D stops scrolling. Must be lower than Parallax2D.LimitEnd minus the viewport size to work.
LimitEndProperty
public Vector2 LimitEnd { get; set; }Bottom-right limits for scrolling to end. If the camera is outside of this limit, the Parallax2D will stop scrolling. Must be higher than Parallax2D.LimitBegin and the viewport size combined to work.
RepeatSizeProperty
public Vector2 RepeatSize { get; set; }Repeats the Texture2D of each of this node's children and offsets them by this value. When scrolling, the node's position loops, giving the illusion of an infinite scrolling background if the values are larger than the screen size. If an axis is set to 0, the Texture2D will not be repeated.
RepeatTimesProperty
public int RepeatTimes { get; set; }Overrides the amount of times the texture repeats. Each texture copy spreads evenly from the original by Parallax2D.RepeatSize. Useful for when zooming out with a camera.
ScreenOffsetProperty
public Vector2 ScreenOffset { get; set; }Offset used to scroll this Parallax2D. This value is updated automatically unless Parallax2D.IgnoreCameraScroll is true.
ScrollOffsetProperty
public Vector2 ScrollOffset { get; set; }The Parallax2D's offset. Similar to Parallax2D.ScreenOffset and Entity2D.Position, but will not be overridden.
Note: Values will loop if Parallax2D.RepeatSize is set higher than 0.
ScrollScaleProperty
public Vector2 ScrollScale { get; set; }Multiplier to the final Parallax2D's offset. Can be used to simulate distance from the camera.
For example, a value of 1 scrolls at the same speed as the camera. A value greater than 1 scrolls faster, making objects appear closer. Less than 1 scrolls slower, making objects appear further, and a value of 0 stops the objects completely.
Methods20
GetAutoscrollVector2
public Vector2 GetAutoscroll();Vector2GetFollowViewportbool
public bool GetFollowViewport();boolGetLimitBeginVector2
public Vector2 GetLimitBegin();Vector2GetLimitEndVector2
public Vector2 GetLimitEnd();Vector2GetRepeatSizeVector2
public Vector2 GetRepeatSize();Vector2GetRepeatTimesint
public int GetRepeatTimes();intGetScreenOffsetVector2
public Vector2 GetScreenOffset();Vector2GetScrollOffsetVector2
public Vector2 GetScrollOffset();Vector2GetScrollScaleVector2
public Vector2 GetScrollScale();Vector2IsIgnoreCameraScrollbool
public bool IsIgnoreCameraScroll();boolSetAutoscrollvoid
public void SetAutoscroll(Vector2 autoscroll);| Name | Type | Default |
|---|---|---|
autoscroll | Vector2 | — |
SetFollowViewportvoid
public void SetFollowViewport(bool follow);| Name | Type | Default |
|---|---|---|
follow | bool | — |
SetIgnoreCameraScrollvoid
public void SetIgnoreCameraScroll(bool ignore);| Name | Type | Default |
|---|---|---|
ignore | bool | — |
SetLimitBeginvoid
public void SetLimitBegin(Vector2 offset);| Name | Type | Default |
|---|---|---|
offset | Vector2 | — |
SetLimitEndvoid
public void SetLimitEnd(Vector2 offset);| Name | Type | Default |
|---|---|---|
offset | Vector2 | — |
SetRepeatSizevoid
public void SetRepeatSize(Vector2 repeatSize);| Name | Type | Default |
|---|---|---|
repeatSize | Vector2 | — |
SetRepeatTimesvoid
public void SetRepeatTimes(int repeatTimes);| Name | Type | Default |
|---|---|---|
repeatTimes | int | — |
SetScreenOffsetvoid
public void SetScreenOffset(Vector2 offset);| Name | Type | Default |
|---|---|---|
offset | Vector2 | — |
SetScrollOffsetvoid
public void SetScrollOffset(Vector2 offset);| Name | Type | Default |
|---|---|---|
offset | Vector2 | — |
SetScrollScalevoid
public void SetScrollScale(Vector2 scale);| Name | Type | Default |
|---|---|---|
scale | Vector2 | — |