Parallax 2D only one Sprite is scrolling

Godot Version

4.3

Question

Hello,

I am trying to use the new parallax 2D node but I am encountering the problem that I have two parallax layers and the second layer isn´t scrolling even though set so in the code. The position.y of Sprite2D2 just doesn´t change at all. I have checked via print.
The second layer also works fine when I add the texture beforehand. It seems to only fail with the texture uploaded via code.

Does anyone have an idea why?
image

extends Node2D

@onready var viewport_size := Vector2(Globals.viewport_dimensions)
@onready var current_texture = load("res://Assets/Background/Colorful_Nebulas.jpg")
var next_texture
var backgrounds = {}
# Called when the node enters the scene tree for the first time.
func _ready():
	
	$Spacefog/Sprite2D.texture = current_texture
	$Spacefog/Sprite2D.offset.y = (-1 * $Spacefog/Sprite2D.texture.get_size().y) + viewport_size.y
	
	
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	
	#set parallax effect for spacefog
	$Spacefog.scroll_offset.y += 1200*delta # pixels per second that background moves
	$Spacefog2.scroll_offset.y += 1200*delta # pixels per second that background moves

	print("position: ", $Spacefog2/Sprite2D2.position.y) # Debug print

func _on_timer_next_timeout() -> void:
	next_texture = load("res://Assets/Background/desert_Background.png")
	$Spacefog2/Sprite2D2.texture = next_texture
	$Spacefog2/Sprite2D2.position.y = $Spacefog/Sprite2D.position.y - $Spacefog/Sprite2D.texture.get_size().y*2

Best regards!

You have set offsets, which shifts the initial scroll position, not the pixels per second as your comment suggests. You appear to have not set the scroll_scale, which sets the speed at which it scrolls relative to the camera movement.

But scroll_offset is working with the first layer without any problem.
scroll_scale is set to (1,1) as per standard. Also the second layer works fine when I upload the texture in the inspector.

If you provided some of the settings you currently have for your parallax nodes we can help more, but here are a few things I can comment on:

  1. scroll_offset moves the Parallax2D node and is clamped by your repeat_size.
  2. I’m not sure why you specifically have it set to 1200 and why you’re updating it twice, but you definitely wouldn’t see any movement in position because it’s the Parallax2D that’s moving, not its children.
  3. Parallax2D has an auto_scroll property specifically for this use, and its values are based on px/s, so no extra logic is needed.

For more information, please take a look at the tutorial linked in the documentation.

1 Like