change dynamic font dynamically

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By nonomiyo

Hello !

I set up 2 DynamicFonts ( engfont.tres for English and japfont.tres for Japanese) and I would like to be able to switch my label’s font depending on the language option selected.

Basically, this is what I’d like to do :

func _on_japanese_pressed():
   var typo = load("res://fonts/japfont.tres") 
   label.font = typo
   label.text =  "日本語 (japanese)"

Invalid set index ‘font’ (on base: ‘Label’) with value of type ‘DynamicFont’

What is the correct way of putting it please ?
thank you !

Try defining one or several fallback fonts in the English DynamicFont resource. This way, you won’t have to define create font resources and the font will be swapped automatically when the glyph cannot be found in the original (English) font.

Calinou | 2018-09-18 15:56

:bust_in_silhouette: Reply From: Oen44

That should help you out - Localizing resources. Set different font for different language.

thanks, I didn’t want to get into this translation option as I already did all the translations myself, but it is super useful actually to be able to switch assets so easily ! :smiley:

nonomiyo | 2018-09-18 11:41

:bust_in_silhouette: Reply From: nonomiyo

I managed to do what I wanted :

   func _on_japanese_pressed():
       var fnt = load("res://fonts/japfont.tres")
       get_node("label").add_font_override("font", fnt)
       label.text =  "日本語 (japanese)"

I add:

var fnt = load("res://assets/fonts/osans_font.tres")
var name_label =
name_label.text =

ivan_f | 2019-01-25 17:26