How to change the FontFamily ingame?
Hi,
We're currently using a ResourceDictionary that includes the default font used by our game, something like this:
We want to change this MainFont depending on TWO things:
·The language selected, for example if the user selects Japanese we want to use another font, if they select Korean another, etc...
·The user can also select between two different fonts for the english language, for example they can play with MainFontA or MainFontB.
I'm not sure if Noesis supports this and what would be the best way to handle this. Any pointers would be greatly appreciated.
We're currently using a ResourceDictionary that includes the default font used by our game, something like this:
Code: Select all
<FontFamily x:Key="MainFont">/Assets/UI/Fonts/#MainFont</FontFamily>·The language selected, for example if the user selects Japanese we want to use another font, if they select Korean another, etc...
·The user can also select between two different fonts for the english language, for example they can play with MainFontA or MainFontB.
I'm not sure if Noesis supports this and what would be the best way to handle this. Any pointers would be greatly appreciated.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: How to change the FontFamily ingame?
Hello,
One way to achieve what you want is to merge a different dictionary depending on the selected language/font. For example, you can have a master dictionary for the fonts in the Application Resources, call it Fonts.xaml, and then have specific dictionaries for each language/font, like Fonts.English.xaml:
Then you can reference that font in your root page (or anywhere you need) with a DynamicResource:
And when the selected language changes you just update the merged dictionary:
Could something like this work for you?
One way to achieve what you want is to merge a different dictionary depending on the selected language/font. For example, you can have a master dictionary for the fonts in the Application Resources, call it Fonts.xaml, and then have specific dictionaries for each language/font, like Fonts.English.xaml:
Code: Select all
Fonts.xaml
----------
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Fonts.English.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Fonts.English.xaml
------------------
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<FontFamily x:Key="MainFont">Fonts/#Font 1</FontFamily>
</ResourceDictionary>
Fonts.French.xaml
-----------------
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<FontFamily x:Key="MainFont">Fonts/#Font 2</FontFamily>
</ResourceDictionary>Code: Select all
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FontFamily="{DynamicResource MainFont}">
...
</Page>Code: Select all
void ChangeLanguageFont(ResourceDictionary fontsDictionary, string languagePath)
{
fontsDictionary.MergedDictionaries.Clear();
ResourceDictionary lang = (ResourceDictionary)Noesis.GUI.LoadXaml(languagePath);
fontsDictionary.MergedDictionaries.Add(lang);
}Re: How to change the FontFamily ingame?
This is exactly what I needed, thanks!
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: How to change the FontFamily ingame?
Great, marking this as solved.
Who is online
Users browsing this forum: Bing [Bot] and 5 guests