Parallax2D
A node used to create a parallax scrolling background.
Parallax2D.swift:20class Parallax2D
A Parallax2D
is used to create a parallax effect. It can move at a different speed relative to the camera movement using scrollScale
. This creates an illusion of depth in a 2D game. If manual scrolling is desired, the Camera2D
position can be ignored with ignoreCameraScroll
.
Superclasses
class Node2D
A 2D game object, inherited by all 2D-related nodes. Has a position, rotation, scale, and Z index.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
var autoscroll: Vector2
Velocity at which the offset scrolls automatically, in pixels per second.
var followViewport: Bool
If
true
, thisParallax2D
is offset by the current camera’s position. If theParallax2D
is in aCanvasLayer
separate from the current camera, it may be desired to match the value withfollowViewportEnabled
.var ignoreCameraScroll: Bool
If
true
,Parallax2D
’s position is not affected by the position of the camera.var limitBegin: Vector2
Top-left limits for scrolling to begin. If the camera is outside of this limit, the
Parallax2D
stops scrolling. Must be lower thanlimitEnd
minus the viewport size to work.var limitEnd: Vector2
Bottom-right limits for scrolling to end. If the camera is outside of this limit, the
Parallax2D
will stop scrolling. Must be higher thanlimitBegin
and the viewport size combined to work.var repeatSize: Vector2
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 to0
, theTexture2D
will not be repeated.var repeatTimes: Int32
Overrides the amount of times the texture repeats. Each texture copy spreads evenly from the original by
repeatSize
. Useful for when zooming out with a camera.var screenOffset: Vector2
Offset used to scroll this
Parallax2D
. This value is updated automatically unlessignoreCameraScroll
istrue
.var scrollOffset: Vector2
The
Parallax2D
’s offset. Similar toscreenOffset
andposition
, but will not be overridden.var scrollScale: Vector2
Multiplier to the final
Parallax2D
’s offset. Can be used to simulate distance from the camera.