–1 vote

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

Godot version 3.2.3.stable
in Engine by (142 points)

1 Answer

0 votes

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.

by (570 points)

I want this because I have no Idea how to make shadows working good with parallax background. I don't know why Shadows = Background :/
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

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.

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.