Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Mike Gringauz | |
Old Version | Published before Godot 3 was released. |
Hi!
In general…
When I place a Sprite inside a Control with all anchors set to Center it works fine when the game window size changes, that is the Sprite stays in the center of the screen.
How to achieve the same centering of ParallaxBackground inside a Control? It seems to stay top-left anchored…
To be concrete…
I have the following scene hierarchy:
Also I run the following function on viewport “size_changed” signal to keep game screen responsive to fit multiple resolutions as described in QA https://forum.godotengine.org/9947/responsive-to-fit-multiple-resolutions:
func on_viewport_size_changed ():
var size = OS.get_window_size()
scale_factor = SAFE_SIZE.y / size.y
window_size = Vector2 (size.x * scale_factor, SAFE_SIZE.y)
if window_size.x < SAFE_SIZE.x:
scale_factor = SAFE_SIZE.x / window_size.x
window_size = Vector2 (SAFE_SIZE.x, window_size.y * scale_factor)
if window_size.y < SAFE_SIZE.y:
scale_factor = SAFE_SIZE.y / window_size.y
window_size = Vector2 (window_size.x * scale_factor, SAFE_SIZE.y)
viewport.set_size_override( true, window_size )
And it seems to work fine with “ordinary” sprites, that is ship-sprite and background-sprite stays always centered inside a Control:
No matter how window size have changed:
But not with parallax background which stays always top-left anchored even if put inside a Control with anchors set to Center:
No matter how window size have changed:
Thanks!
Why are you using a parallax background (which is a CanvasLayer) inside a Control? I’m not sure it was ever intented to do that.
Zylann | 2016-12-02 11:34
I’m placing ParallaxBackgrounf inside a Control because I want this behavior in my game: https://forum.godotengine.org/9947/responsive-to-fit-multiple-resolutions
Mike Gringauz | 2016-12-02 11:50
I still don’t get why you want parallax background inside a Control (I see none in the example you gave). Is that a tiled background? Do you have a screenshot?
Zylann | 2016-12-02 18:23
Added screenshots and more details.
Mike Gringauz | 2016-12-09 07:56
You need control because parallax layers ignore camera zoom while dealing with multiple resolutions. Putting it inside a control works as workaround. I don’t know if it behaviour is intended or not, but it is very annoying.
lukas | 2016-12-09 09:11
Seems like ParallaxBackground works against the rest of Godot’s principles.
Mike Gringauz | 2016-12-09 12:04