Hello!
I'd like to support 2 different aspect ratios - widescreen and 4:3 in my game, but I don't know how to:
a) Toggle between them.
b) Detect whether the user has a widescreen display.
Any ideas?
How do I detect aspect ratio and change resolution?
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.
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.
- Kia
- Eileen-Class Veteran
- Posts: 1040
- Joined: Fri Aug 01, 2014 7:49 am
- Deviantart: KiaAzad
- Discord: Kia#6810
- Contact:
Re: How do I detect aspect ratio and change resolution?
edit: I was way off ^_^
Last edited by Kia on Thu Jun 11, 2015 12:47 am, edited 1 time in total.
Re: How do I detect aspect ratio and change resolution?
Try:
in options.rpy:
You'll also have to make sure all game elements/resources are structured in way that can support both without displacement. That said, you can place a lot more checks trying to get resolution info from APIs getting it directly from the OS in an unlikely case that PyGame failed to log it in for some reason. Google what to use for every OS and check if Ren'Pys Python has the required modules. Obviously you can always have a default to revert to in the else clause...
I didn't try the code so there could be some spelling errors, but the approach should be sound enough.
*And keep in mind that Ren'Py scales it's window reasonably well. Sometimes having a bit of black space on the sides/top+bottom in fullscreen mode is preferable to messing with resolutions, in my opinion it's always the case unless you're making an expensive commercial game of some sorts.
in options.rpy:
Code: Select all
init python hide:
info = renpy.display.info
width, height = info.current_w, info.current_h
if round(float(width)/height, 2) == 1.78:
config.screen_width, config.screen_height = 1280, 720
elif round(float(width)/height, 2) == 1.33:
config.screen_width, config.screen_height = 800, 600
else:
raise Exception("Get a Monitor with 16:9 or 4:3 resolutions to play this game!") # Or pick a default ;)
I didn't try the code so there could be some spelling errors, but the approach should be sound enough.
*And keep in mind that Ren'Py scales it's window reasonably well. Sometimes having a bit of black space on the sides/top+bottom in fullscreen mode is preferable to messing with resolutions, in my opinion it's always the case unless you're making an expensive commercial game of some sorts.
- PyTom
- Ren'Py Creator
- Posts: 16096
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: How do I detect aspect ratio and change resolution?
That last bit of code seems terrible - 16:10 monitors are common, and I had a 5:4 monitor once.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: How do I detect aspect ratio and change resolution?
LoL
That's what the slimy face was for
That's what the slimy face was for
Re: How do I detect aspect ratio and change resolution?
Bump on this.
This code seems perfect me, but i have an error when i launch the application :
AttributeError: 'NoneType' object has no attribute for 'current_w'
It seems that the function returns nothing.
This code seems perfect me, but i have an error when i launch the application :
AttributeError: 'NoneType' object has no attribute for 'current_w'
It seems that the function returns nothing.
Re: How do I detect aspect ratio and change resolution?
It worked at the time of this post, this is not directly exposed to developers so there is a chance that something was changed internally or you are on an OS that doesn't return anything meaningful to pygame for whatever reason. You can try accessing os directly or figure out why you info is None now.
Something like this may still get it from pygame, I guess it was changed at some point and moved to interface class:
Something like this may still get it from pygame, I guess it was changed at some point and moved to interface class:
Code: Select all
init python:
import pygame
meow = pygame.display.init()
meow = pygame.display.Info()
width, height = meow.current_w, meow.current_h
if round(float(width)/height, 2) == 1.78:
config.screen_width, config.screen_height = 1280, 720
elif round(float(width)/height, 2) == 1.33:
config.screen_width, config.screen_height = 800, 600
else:
config.screen_width, config.screen_height = 800, 600
Re: How do I detect aspect ratio and change resolution?
Works perfectly ! Thanks !
Who is online
Users browsing this forum: Ocelot