Hi all,

Say for example that I want my game to have the same size characters on a 1920x1080 (Full HD) screen, and a 3840x2160 (4K) screen? Right now I have a bunch of RigidBody2Ds with Sprites. I would like when my game is on the 4K version, the sprites are displayed full resolution (no stretching) . I could provide differently scaled sprites for both versions of the game. But I want the CollisionPolygon2Ds to be the right size to match the Sprites. Any thoughts about the best way to handle this?

One way to handle multiple screen resolutions is to set the mode and aspect of the project settings to (general -> display -> window) to 2d and keep, which will make the screen aspect ratio the same across different resolutions. That should work around issues where the difference in screen size changes the viewport.

For the sprites themselves, I dunno. I think what I would try initially is to load the different sprite sizes through GDScript in the _ready function for each RigidBody2D node, storing the expected scale and texture in a list/dictionary that is predefined within the script. Something like this (untested pseudo GDScript code):

var sprites = {
	"4K": {
			"Sprite_01": [preload("res://path_to_hd_image.png"), Vector2(0.2, 0.2)]
		}
	"HD": {
			"Sprite_01": [preload("res://path_to_sd_image.png"), Vector2(1, 1)]
		}
}
func _ready():
	var resolution = "HD"
	var sprite_name = "Sprite_01"
	if (get_tree().root.size.x > 1920):
		resolution = "4K"
	
	get_node("Sprite").texture = sprites[resolution][sprite_name ][0]
	get_node("Sprite").scale = sprites[resolution][sprite_name ][1]

Or another way you could do it is instance different scenes based on the resolution. You'd need to write code that checks the screen resolution and based on the resolution, instances the scene with the correct sprite(s). This would require more scenes though, so it might not be worth it.

Finally, you could just use the high resolution sprites everywhere, since at HD it will just render the textures at a lower resolution. This would raise the performance requirements of your game a bit, but the ease of development might be worth it.

Those are just a few ways I might go about tackling the issue if I was developing for both HD and 4K. There might be better and easier ways of handling it, but hopefully the above is of some help :smile:

@TwistedTwigleg said: One way to handle multiple screen resolutions is to set the mode and aspect of the project settings to (general -> display -> window) to 2d and keep, which will make the screen aspect ratio the same across different resolutions. That should work around issues where the difference in screen size changes the viewport.

For the sprites themselves, I dunno. I think what I would try initially is to load the different sprite sizes through GDScript in the _ready function for each RigidBody2D node, storing the expected scale and texture in a list/dictionary that is predefined within the script. Something like this (untested pseudo GDScript code):

var sprites = {
	"4K": {
			"Sprite_01": [preload("res://path_to_hd_image.png"), Vector2(0.2, 0.2)]
		}
	"HD": {
			"Sprite_01": [preload("res://path_to_sd_image.png"), Vector2(1, 1)]
		}
}
func _ready():
	var resolution = "HD"
	var sprite_name = "Sprite_01"
	if (get_tree().root.size.x > 1920):
		resolution = "4K"
	
	get_node("Sprite").texture = sprites[resolution][sprite_name ][0]
	get_node("Sprite").scale = sprites[resolution][sprite_name ][1]

Or another way you could do it is instance different scenes based on the resolution. You'd need to write code that checks the screen resolution and based on the resolution, instances the scene with the correct sprite(s). This would require more scenes though, so it might not be worth it.

Finally, you could just use the high resolution sprites everywhere, since at HD it will just render the textures at a lower resolution. This would raise the performance requirements of your game a bit, but the ease of development might be worth it.

Those are just a few ways I might go about tackling the issue if I was developing for both HD and 4K. There might be better and easier ways of handling it, but hopefully the above is of some help :smile:

Hey thanks, I will be trying this out and will update as soon as I'm done?

This is really helpful. Thanks. A followup question. What if I just use the same high res sprites, and "zoom" the camera out, so that they are the same size for high and low res? Is there a way to do that without scaling each individual sprite?

I suppose you could zoom the camera out, but you might have issues with scale for things like CollisionShape2D nodes so they fit the high resolution sprites and/or make separate nodes for each scale. The other issue you might have with zooming the camera out is in code, as things like movement will need to be scaled up so both the high and low resolution versions move at the same speed. It is doable though, but depending on your project it might end up being a fair amount of work.

Ok, that's exactly what I was looking for. I like the swapping and scaling Sprites idea, shouldn't be hard.

Another followup. How do I ensure that my Sprites are 1 to 1 scaled to the screen? Does it matter if I set the settings in Display->Window->Width/Height to 1920x1080 and then for 4K I just scale the Sprites down by .5 or if I set the settings in Display->Window to 3840x2160 and then for FullHD scale the sprites up by 2??

I don't know for sure, but I think either way should work. Ultimately the important part is that the pixels are the correct size for each resolution, and either of the methods you listed above should give the correct pixel size. I would maybe also enable Use Pixel Snap (Rendering -> Quality), which will reduce scale-based pixel interpolation, so players with screen resolutions in between HD and 4K get clear looking pixels.

3 years later