Allow player to change font (Opendyslexic or else)
Posted: Fri Jan 24, 2020 3:32 pm
Hi guys, accessibility is important, so you might be interest to add an OpenDyslexic font to your game, or even just several option (a fancy one and a sans serif one for example).
→ If you want to change only the in game font please look at this great tutorial about font selection from BáiYù.
→ If you want to change all the font (so in game, interface like menu button and character name), there is two possibility :
1) All your fonts are the same
2) All your fonts are different (more likely).
1) All your font are the same.
Step 1 : put all your font, including OpenDyslexic into your game folder. (You can find it here)
Step 2 : Go into your gui.rpy file, and look for this piece of code and delete it.
step 3 : Instead put :
(replace DejaVuSans by your own font. Please be careful, there is too common format .ttf or .otf don't forget to change it accordingly ! All fonts must be the same otherwise look at the second part of the tutorial).
step 4 : Go into your screen.rpy, and look for your preference screen find this line :
(Once again, don't forget to change the DejaVuSans by our own font.)
Bonus : Add more font choices.
You can add as many font choice you want, at the end of the previous code inside the preference screen just add this line as much as you need :
2) All your font are different (so a font for in game, a font for buttons and so on.)
Step 1 : put all your font, including OpenDyslexic into your game folder. (You can find it here)
Step 2 : Go into your gui.rpy file, and look for this piece of code and delete it.
step 3 : Instead put :
(replace DejaVuSans by your own fonts. Please be careful, there is too common format .ttf or .otf don't forget to change it accordingly !)
step 4 : go into your screen.rpy, and look for your preference screen find this line :
(Once again, don't forget to change the 3 DejaVuSans by our own fonts.)
Bonus : Add more font choices.
You can add as many font choice you want, at the end of the previous code inside the preference screen just add this line as much as you need :
It can be 3 different font if you wish.
And that's all, I hope it will be useful !
3) Adjust font size
OpenDyslexic is a font really bigger than other traditional font. It can then cause problem (text too big for the texbox, overlaping in game menu and so on). There is a simple solution to fix it, into your gui.rpy just at the begining after the :
add (don't forget to indent) :
It will automaticaly scale.to your actual font. (You can change the number if you want it bigger but .7 is normally a good ratio).
Will automatically reduce the line spacing.
→ If you want to change only the in game font please look at this great tutorial about font selection from BáiYù.
→ If you want to change all the font (so in game, interface like menu button and character name), there is two possibility :
1) All your fonts are the same
2) All your fonts are different (more likely).
1) All your font are the same.
Step 1 : put all your font, including OpenDyslexic into your game folder. (You can find it here)
Step 2 : Go into your gui.rpy file, and look for this piece of code
Code: Select all
## Fonts and Font Sizes ########################################################
## The font used for in-game text.
define gui.text_font = "DejaVuSans.ttf"
## The font used for character names.
define gui.name_text_font = "DejaVuSans.ttf"
## The font used for out-of-game text.
define gui.interface_text_font = "DejaVuSans.ttf"`step 3 : Instead put :
Code: Select all
## The font used for in-game text.
define gui.text_font = gui.preference("font", "DejaVuSans.ttf")
## The font used for character names.
define gui.name_text_font = gui.preference("font", "DejaVuSans.ttf")
## The font used for out-of-game text.
define gui.interface_text_font = gui.preference("font", "DejaVuSans.ttf")step 4 : Go into your screen.rpy, and look for your preference screen find this line :
Then add :## Additional vboxes of type "radio_pref" or "check_pref" can be
## added here, to add additional creator-defined preferences.
Code: Select all
vbox:
style_prefix "check"
label _("Font")
textbutton _("Default") action gui.SetPreference("font", "DejaVuSans.ttf")
textbutton _("OpenDyslexic") action gui.SetPreference("font", "OpenDyslexic.otf")Bonus : Add more font choices.
You can add as many font choice you want, at the end of the previous code inside the preference screen just add this line as much as you need :
Code: Select all
textbutton _("OpenDyslexic") action gui.SetPreference("font", "Yourfont.otf")2) All your font are different (so a font for in game, a font for buttons and so on.)
Step 1 : put all your font, including OpenDyslexic into your game folder. (You can find it here)
Step 2 : Go into your gui.rpy file, and look for this piece of code
Code: Select all
## Fonts and Font Sizes ########################################################
## The font used for in-game text.
define gui.text_font = "DejaVuSans.ttf"
## The font used for character names.
define gui.name_text_font = "DejaVuSans.ttf"
## The font used for out-of-game text.
define gui.interface_text_font = "DejaVuSans.ttf"`step 3 : Instead put :
Code: Select all
## The font used for in-game text.
define gui.text_font = gui.preference("font_1", "DejaVuSans.ttf")
## The font used for character names.
define gui.name_text_font = gui.preference("font_2", "DejaVuSans.ttf")
## The font used for out-of-game text.
define gui.interface_text_font = gui.preference("font_3", "DejaVuSans.ttf")step 4 : go into your screen.rpy, and look for your preference screen find this line :
Then add :## Additional vboxes of type "radio_pref" or "check_pref" can be
## added here, to add additional creator-defined preferences.
Code: Select all
vbox:
style_prefix "check"
label _("Font")
textbutton _("Default") action [gui.SetPreference("font_1", "DejaVuSans.ttf"), gui.SetPreference("font_2", "DejaVuSans.ttf"), gui.SetPreference("font_3", "DejaVuSans.ttf")]
textbutton _("OpenDyslexic") action [ gui.SetPreference("font_1", "OpenDyslexic.otf"), gui.SetPreference("font_2", "OpenDyslexic.otf"), gui.SetPreference("font_3", "OpenDyslexic.otf")]Bonus : Add more font choices.
You can add as many font choice you want, at the end of the previous code inside the preference screen just add this line as much as you need :
Code: Select all
textbutton _("Font name") action [ gui.SetPreference("font_1", "YourFont.otf"), gui.SetPreference("font_2", "YourFont.otf"), gui.SetPreference("font_3", "YourFont.otf")And that's all, I hope it will be useful !
3) Adjust font size
OpenDyslexic is a font really bigger than other traditional font. It can then cause problem (text too big for the texbox, overlaping in game menu and so on). There is a simple solution to fix it, into your gui.rpy just at the begining after the :
Code: Select all
init python:Code: Select all
config.ftfont_scale["OpenDyslexic.otf"] = .7Code: Select all
config.ftfont_vertical_extent_scale["OpenDyslexic.otf"] = .8(Turorial based on this great doc : https://www.renpy.org/doc/html/gui_advanced.html)
(To use this tutorial, your renpy version should be 6.99.4 or more)
Thanks to Rob in the Renpy discord for the scaling solution