0 votes

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

in Engine by (117 points)

3 Answers

0 votes

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

by (59 points)

They are on two separate canvas layers

0 votes

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

extends Node
 var FieldPos = Vector2()
by (59 points)
0 votes

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.

by (840 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.