It's possible to make ParallaxBackground but not like background type?

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

It’s possible to make ParallaxBackground with parallax properties bun not like background type (for example like sprite)?

:bust_in_silhouette: Reply From: djmick

I have no idea why you would want to do this, the parallax node is really good and helps you mirror and set speeds specifically to scroll at and also handles many different layers, but if you really wanted to use a sprite, you would first have to draw a sprite the size of the canvas with the background you wanted, then you would have to duplicate it horizontally so that it is now the same height as the canvas but twice the width, and each half is equal. Then you could put that as the texture to a sprite, and write this code:

extends Sprite

func _ready():
	position.x = 0
	
func _process(delta):
	position.x -= 100 * delta
	if position.x <= -get_viewport().size.x:
		position.x = 0
	

Note that is you are using pixel art, the viewport is more than likely much bigger than the actual window, so you would have to replace the get_viewport().size.x with the actual width of your window. Now you have a scrolling, repeating sprite, but this automatically moves and isn’t actually parallax, this was just a test for the mirroring. You would then have to probably have to connect it to the camera in some way, and the you would have to make it move the opposite direction of the player at half the speed so that with the player moving for example 10 pixels per second one way and the background moving 5 pixels per second the other way on top of that, the player would seem to be moving at 10 pixels per second while the background was moving at 5 pixels per second giving a parallax effect. If you had screen shake, though, this effect would be broken because normally you would want the screen shake to also keep the parallax effect, but we would have to set that up too not only on the horizontal axis, but we would have to set up the vertical axis by redrawing the sprite doubled in the vertical direction. You would also more than likely have to this for multiple layers. Sorry if this seemed unnecessary, but please use the actual parallax node. It is there for a reason and it is super useful. Unless you have a legit reason not to use it, just specify that in the question so we can not only understand better, but help answer your question better.

I want this because I have no Idea how to make shadows working good with parallax background. I don’t know why Shadows = Background :confused:
I want to implement limitation of vision with working parallax background
When I turn on parallax, this is what comes out:
no description
But when I use standard sprite, shadows is working well, but without parallax effect:
no description

Krasapan | 2021-01-26 16:19

Oh okay. Sorry for the over the top original answer, honestly I’ve never worked with shadows before and I can’t see your pictures, sorry.

djmick | 2021-01-26 16:28