Topic was automatically imported from the old Question2Answer platform.
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():
set_process(true)
pass
func _process(delta):
field.position.x -= 5
sky.position.x -= 7
pass
but that doesn’t work, it just makes the texture pass along
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.