Hi there!
Earlier on in the course, I wanted to achieve parallax scrolling only when the player is in motion
I went with:
extends ParallaxBackground
@onready var sprite = $ParallaxLayer/Sprite2D
@onready var scroll_speed = 20
@export var bg_texture: CompressedTexture2D = preload(“res://Assets/textures/bg/Blue.png”)func _ready():
sprite.texture = bg_texturefunc _process(delta):
var direction = Input.get_axis(“move_left”, “move_right”)
if direction > 0:
sprite.region_rect.position += delta * Vector2(scroll_speed, 0)
if direction < 0:
sprite.region_rect.position += delta * Vector2(-scroll_speed, 0)
if sprite.region_rect.position >= Vector2(64, 64):
sprite.region_rect.position = Vector2.ZERO
However, this poses an issue when instancing the BG for the main menu - there is no player input to capture.
How would one go about having the scroll pattern automate if we are on the main menu?
Thanks!
/Weeg