Having problems with Infinitive Background Scrolling

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

I am having problems with the background movement (without camera) in my game, i have two backgrounds: field and sky, and set both of them with region and flags with repeat, mipmaping, and filter. and i wrote a code for both to move

extends Node

onready var field = get_node("canvas_one/field")
onready var sky   = get_node("canvas_two/sky")

func _ready():

func _process(delta):
    field.position.x -= 5
    sky.position.x -= 7

but that doesn’t work, it just makes the texture pass along

:bust_in_silhouette: Reply From: koigx

Are they on the same canvas layer or on two separate layers? Sorry it wasn’t clear from your original post

They are on two separate canvas layers

Dava | 2018-02-10 13:08

:bust_in_silhouette: Reply From: koigx

I think Godot doesn’t know yet that it’s a Vector2 – How about this:

extends Node
 var FieldPos = Vector2()
:bust_in_silhouette: Reply From: Footurist

You’ve ran into a misconception of how background scrolling works. What you do is, you simply move the texture off the viewport. What you desire is moving the actual viewport. Doing this will trigger Godot to repeat the texture. You can do this if you attach a camera to the object, that’s moved by the player. If there is no such player, you can just create a camera as a child of a Node2D and move the Node2D via script. If you got things like that going on it’s always best to use ParallaxBackground with ParallaxLayer as children. These will do a lot of the dirty work. However, don’t use them if you work a lot with zooming in and out, since they appear to struggle with this. Write your own ParallaxBackground for this.