this post was submitted on 19 Dec 2024
16 points (100.0% liked)

Godot

6007 readers
6 users here now

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

[email protected]

Credits

founded 2 years ago
MODERATORS
 

I am experimenting with creating a pixel-art mobile game in Godot. I am having trouble with the viewport size regarding the pixel art assets. I've learned that I should set the scaling mode to integer, which adds black bars to the screen. My plan to get rid of the black bars is as follows:

  1. Find a way to resize the main viewport dynamically in runtime
  2. Calculate, based on the device's size, what size the viewport should be
  3. Apply that calculation when appropriate

Before I even try to get a calculation like that going, I want to make sure I can change the viewport's size in the code, which I couldn't figure out myself. I have tried the following:

  • Changing the project settings in a _ready function: Does nothing
  • Changing the project settings in a _process function: Does nothing
  • Setting get_viewport().size in a _ready function: Does nothing
  • Setting get_viewport().size in a _process function: Changes the size of the viewport, but without expanding it
  • Setting get_window().size in a _ready function: Does nothing

What else can I try?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 1 points 2 days ago (4 children)

@roydbt You can change the window size if you need to by using get_window.size, but you should also use the Window.content_scale_size for further adjusments

[–] [email protected] 1 points 2 days ago (1 children)

And where should I put that? In a _reaay or a _process?

[–] [email protected] 1 points 1 day ago (1 children)

@roydbt I assume you want to do scaling once at start so ready would be the best choice since process is called many times every second

[–] [email protected] 1 points 1 day ago (1 children)

Thanks, setting get_window().content_scale_size = DisplayServer.window_get_size() / 3 works! Now I only have to figure out what 3 stands for

[–] ICastFist 3 points 19 hours ago

By the way, you can set up and use a Global script that is accessible from any node (set it up from Project Settings -> Autoload tab), it can also contain a _ready() function that will run one time once the game is loaded

On a project of mine, I use this function to change between different window modes, maybe one of these could make your think work? Possibly setting the window to fullscreen would work as you intend.

func _on_windowtype_item_selected(index):
	match index:
		0: #Windowed mode
			get_tree().root.mode = Window.MODE_WINDOWED
			get_window().size = get_viewport().size #Possibly what you were looking for all this time
## alternatively, get_window().size = DisplayServer.window_get_size() #should make the game window the same size as the whole screen
			get_tree().root.borderless = false
		1: #Fullscreen mode
			get_tree().root.mode = Window.MODE_FULLSCREEN #easiest full screen
		2: #Windowed Borderless mode
			get_tree().root.mode = Window.MODE_WINDOWED
			get_tree().root.borderless = true
		3: #Fullscreen Borderless mode
			get_tree().root.mode = Window.MODE_MAXIMIZED
			get_tree().root.borderless = true
load more comments (2 replies)