#Resize sprites to fit when window is fullscreen

20 messages · Page 1 of 1 (latest)

plucky hill
#

I have some UI buttons in a scene that I'd like to be at the top of the screen, always. The UI screen is the first image, but when I use this code in my main scene, the result is the second image. How can I make the UI always at the top (and in the right order)?```swift

main scene script

extends Node2D

func _ready():
var ui_scene = preload("res://Scenes/Top UI Bar.tscn")
var ui_instance = ui_scene.instantiate()
add_child(ui_instance)

craggy kayak
#

Have you set the "Top UI Root" node to occupy the whole screen here?

plucky hill
#

o I don’t think so

#

I’ll try that when I get back

slender quail
#

Unless you really need to, don't instatiate and add_child like this for UI. Instead add it as part of the scene node tree. (It's the chain icon at the top of the scene tree - that says "Instantiate Child Scene" when you hover the mouse over it.)

Then you can use the anchor presets that rsubtil shows in his screenshot.

If you really have to do it via script, then you'll want to add an VBox control, that is set to Full Rect from the Anchor Presets (again - same screenshot). Then add the instantiated control to that VBox. That should place it at the top. (This is probably not the only way to accomplish this though.)

plucky hill
#

turns out it didnt

#

I managed to kind of get it to work by moving the position of the UI scene to the top of the camera’s view, but if they resize the window it doesn’t resize the UI correctly

#

If I run the UI scene itself it works fine, just not when it’s in another scene (only the part of the UI scene which is within the camera’s view can be seen)

slender quail
#

As you found out, the answer is no. Only Control derived nodes will work when you want it to automatically size/place things for UI. You can wrap a Control node around the Node2D node and set the control nodes min size.

cunning oracle
#

Try using a CanvasLayer as the parent of the Control.

plucky hill
#

Would this work?

Node
—Control
    —UI scene
—Node2D
    —Other stuff```
plucky hill
#

Neither of those worked

plucky hill
#

thanks

#

alright I have a new question :D

#

so I have this game scene which works fine if the window is the default small size

#

but as soon as I make the game in fullscreen, it doesnt resize properly :P

#

Resize sprites to fit when window is fullscreen