Godot Version
v4.2.stable.official [46dc27791]
Question
I’m trying to create an autoscrolling layer in my background. I’m not trying to have my entire background autoscroll; just some layers specifically.
Here are the various solutions I’ve tried to get this to work.
SHADER
shader_type canvas_item;
uniform vec2 direction = vec2(1.0, 0.0);
uniform float speed_scale = 0.01;
void fragment(){
vec2 move = direction * TIME * speed_scale;
COLOR = texture(TEXTURE, UV + move);
}
This technically works, but this is extremely inefficient. Shaders don’t have export variables, so I wouldn’t be able to easily edit their scrolling; I would have to make a new shader script every time I wanted the background layer to move differently, and that would be a hassle.
CODE FOR PARALLAXLAYER
extends ParallaxLayer
func _process(delta):
position.x -= 40 * delta
Overwritten by Camera2D, which is also in the scene tree.
CODE FOR SPRITE2D
extends Sprite2D
@export var speed = 40
func _process(delta):
position.x -= speed * delta
That does seem to work at first…until the texture and its mirror move offscreen.
Here’s a video that shows the intended behavior of the background; it uses the first method (the Shader) since it’s only one that works, although the method is rather inefficient for reasons stated above.
Is there a more efficient way (maybe through scripts) to have an individual layer on a background move on its own?