getting lines in my scrolling background

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kaifungamdev

have a scrolling background but I get a random line when it’s playing.
code & video: looping_background.gd · GitHub

another way to do this with a shader
https://www.youtube.com/watch?v=nnuPIX0QbEo

rakkarage | 2023-05-11 00:48

in Godot 4 this method is not possible because they removed import flags

kaifungamdev | 2023-05-11 21:00

You can do it in 4 if you use a TextureRect, set stretch mode to Tile and Texture → Repeat to Enabled. I added another scene to GitHub - rakkarage/TestBackground which shows this too.

rakkarage | 2023-05-11 22:03

oh thanks for that info

kaifungamdev | 2023-05-12 00:03

:bust_in_silhouette: Reply From: rakkarage

It is because when you detect that it needs to be reset it has already passed the end by some amount which needs to be added to the reset value to close the gap.

func _process(delta) -> void:
	_sprite1.position.x += _speed * delta
	_sprite2.position.x += _speed * delta
	if _sprite1.position.x >= _size:
		var add = _sprite1.position.x - _size
		_sprite1.position.x = _reset + add
	if _sprite2.position.x >= _size:
		var add = _sprite2.position.x - _size
		_sprite2.position.x = _reset + add
:bust_in_silhouette: Reply From: kaifungamdev

i fixed it
code :

extends Node2D

var off_screen
var speed = -500
var size
# Called when the node enters the scene tree for the first time.
func _ready():
	off_screen = $BackgroundEmpty.position.x * -1
	size = $BackgroundEmpty.texture.get_size() * $BackgroundEmpty.scale

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	$BackgroundEmpty.position.x += speed * delta
	$BackgroundEmpty2.position.x += speed * delta
	if $BackgroundEmpty.position.x <= off_screen:
		$BackgroundEmpty.position.x = $BackgroundEmpty2.position.x + size.x
	if $BackgroundEmpty2.position.x <= off_screen:
		$BackgroundEmpty2.position.x = $BackgroundEmpty.position.x + size.x