Choosing images according to current resolution

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
CyDementia
Regular
Posts: 27
Joined: Wed Mar 14, 2018 5:54 pm
Contact:

Choosing images according to current resolution

#1 Post by CyDementia » Sat Jun 23, 2018 8:30 am

Hello guys.
I want to do something like this:

Code: Select all

    if Display(1280, 720):
        scene 1280x720_Image1
    elif Display(1920, 1080):
        scene 1920x1080_Image1
This code isn't right and it won't work. This way I just want to explain what I'm trying to do.
Can you please tell me the right way to write this?

kivik
Miko-Class Veteran
Posts: 779
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Choosing images according to current resolution

#2 Post by kivik » Sun Jun 24, 2018 1:13 pm

A few things here:

About the game resolution
- Your game resolution is defined by your gui.init() line in the gui.rpy file by default. Once that's set, that's the resolution of your game.
- When your player resizes their game window, Renpy itself doesn't change resolution as such, it lets the OpenGL engine scale everything accordingly. Some people mistaken that if the player's screen resolution is a certain size, and they fullscreen the game, the game itself changes resolution automatically - that's not the case at all, OpenGL will handle the scaling automatically, so the game's internal resolution stays the same.
- Therefore if your game allows your player to change resolutions - you'd have to code it with variables to begin with. Therefore you can grab the width and height from said variables.

Next we have the issue of what you're trying to achieve - assuming you've got some preferences allowing your players to change your game's resolution, you want to use the correct image size for each resolution. Don't condition checks to display the images! Your game will likely have hundreds if not thousands of instances calling for images - having to write a condition each time is just not an efficient method. Plus, if you're storing 2 versions of your images, one for 1080p and one for 720p, you're unnecessarily bloating up your game's file size.

Instead, just keep the 1080p image files, and use another variable for "zooming" your images. 720p is 66.67% the width and height of the 1080p, so set your zoom variable to 0.67 and have all your images a zoom:

Code: Select all

define img_zoom = 0.67

image image1:
    "image1.png"
    zoom img_zoom
Change the img_zoom to 1 if the game's at 1080p obviously. Then your images should scale accordingly. Alternatively, if you're using pixel art style, you may consider scaling up the 720p raw images to 1.5 - see what works best for you.

CyDementia
Regular
Posts: 27
Joined: Wed Mar 14, 2018 5:54 pm
Contact:

Re: Choosing images according to current resolution

#3 Post by CyDementia » Mon Jun 25, 2018 7:20 am

kivik wrote:
Sun Jun 24, 2018 1:13 pm
A few things here:

About the game resolution
- Your game resolution is defined by your gui.init() line in the gui.rpy file by default. Once that's set, that's the resolution of your game.
- When your player resizes their game window, Renpy itself doesn't change resolution as such, it lets the OpenGL engine scale everything accordingly. Some people mistaken that if the player's screen resolution is a certain size, and they fullscreen the game, the game itself changes resolution automatically - that's not the case at all, OpenGL will handle the scaling automatically, so the game's internal resolution stays the same.
- Therefore if your game allows your player to change resolutions - you'd have to code it with variables to begin with. Therefore you can grab the width and height from said variables.

Next we have the issue of what you're trying to achieve - assuming you've got some preferences allowing your players to change your game's resolution, you want to use the correct image size for each resolution. Don't condition checks to display the images! Your game will likely have hundreds if not thousands of instances calling for images - having to write a condition each time is just not an efficient method. Plus, if you're storing 2 versions of your images, one for 1080p and one for 720p, you're unnecessarily bloating up your game's file size.

Instead, just keep the 1080p image files, and use another variable for "zooming" your images. 720p is 66.67% the width and height of the 1080p, so set your zoom variable to 0.67 and have all your images a zoom:

Code: Select all

define img_zoom = 0.67

image image1:
    "image1.png"
    zoom img_zoom
Change the img_zoom to 1 if the game's at 1080p obviously. Then your images should scale accordingly. Alternatively, if you're using pixel art style, you may consider scaling up the 720p raw images to 1.5 - see what works best for you.
Thank you so much for your detailed explanation and suggestion with zoom.
So it's impossible for Ren'Py to detect current resolution after all? I knew that it relies on gui.init() and scales, but was hoping it can detect new resolution after scaling and there is some command to grab it.

kivik
Miko-Class Veteran
Posts: 779
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Choosing images according to current resolution

#4 Post by kivik » Mon Jun 25, 2018 1:21 pm

If I understand correctly, the scaling is done by OpenGL so Ren'py is agnostic to it, so you wouldn't need to rescale anything if player resizes the window. Just want to be clarify this - if you're concerned about player resizing the game window - don't > it's all handled for you and you absolutely should not rescale the images or they'll be scaled twice and become too big.

It's only if you actually create a preference / option that allows players to physically change the game resolution, that you should use the zoom method.

CyDementia
Regular
Posts: 27
Joined: Wed Mar 14, 2018 5:54 pm
Contact:

Re: Choosing images according to current resolution

#5 Post by CyDementia » Mon Jun 25, 2018 5:47 pm

kivik wrote:
Mon Jun 25, 2018 1:21 pm
If I understand correctly, the scaling is done by OpenGL so Ren'py is agnostic to it, so you wouldn't need to rescale anything if player resizes the window. Just want to be clarify this - if you're concerned about player resizing the game window - don't > it's all handled for you and you absolutely should not rescale the images or they'll be scaled twice and become too big.

It's only if you actually create a preference / option that allows players to physically change the game resolution, that you should use the zoom method.
I had some crazy idea back then which didn't work because of scaling, but found another undependent solution today. Still I'm glad I learned I can zoom. By the way isn't it still better to store all images in 1920x1080 and let them downscale since downscaled images looks better in quality than upscaled ones? Or it just me?

kivik
Miko-Class Veteran
Posts: 779
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Choosing images according to current resolution

#6 Post by kivik » Mon Jun 25, 2018 6:31 pm

Yes, downscaling should in theory look better as you have more information: hence zoom 0.67 which is 1080p down to 720p. However there are instances when it just looks a bit off, especially when you downscale images with high contrasting edges - e.g. graphics. I'm get the impression OpenGL doesn't resample the images when it downscales them, so it can look a bit off.

Post Reply

Who is online

Users browsing this forum: MaydohMaydoh