Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | VincePrinceKing | |
Old Version | Published before Godot 3 was released. |
I use the following script to upscale my graphics in a way my pixel art doesn’t get distorted.
Because my base resolution is pretty small, i have the problem that it has to be upscaled several times to fill big resolutions. This makes fonts and gui pictures, blurry and blocky, because they are just upscaled lowres fonts, where i would prefer a high res one.
What i want to do is, have this upscaled world graphics but still be able to use the real window resolution for my gui layer. I come from Gamemaker, where the GUI layer always used the actual resolution, and I’m looking for a similar solution. Any suggestions on how i could accomplish that?
Thanks in advance on any suggestions.
onready var root = get_tree().get_root()
onready var base_size = root.get_rect().size
onready var display_size=OS.get_screen_size()
onready var maxzoom=1
func _ready():
#calculate base_size:
var calculate_size=display_size
while(calculate_size>=base_size):
calculate_size=display_size/maxzoom
maxzoom+=1
base_size=calculate_size
#make screen resizable
get_tree().connect("screen_resized", self, "_on_screen_resized")
root.set_as_render_target(true)
root.set_render_target_update_mode(root.RENDER_TARGET_UPDATE_ALWAYS)
root.set_render_target_to_screen_rect(root.get_rect())
func _on_screen_resized():
var new_window_size = OS.get_window_size()
var scale_w = max(int(new_window_size.x / base_size.x), 1)
var scale_h = max(int(new_window_size.y / base_size.y), 1)
var scale = min(scale_w, scale_h)
#This offset is needed to keep pixels square
var offset = ((new_window_size / scale) - (new_window_size / scale).floor()) * scale
var offsethalf = (offset * 0.5).floor()
root.set_rect(Rect2(offsethalf, new_window_size / scale))
root.set_render_target_to_screen_rect(Rect2(offsethalf, new_window_size - offset))
I’m looking for an answer to a very similar question—basically, selectively scaling certain parts of the world.
jslater89 | 2016-11-04 03:03