Swap fonts while game is running?
by amaranthia · in Torque Game Builder · 01/16/2007 (10:16 pm) · 4 replies
Has anyone ever swapped fonts while a game is running? In my game, there is an option to change the language from English to Japanese. I think I need to somehow refresh profile.cs in the common directory, but I'm not sure how to do this.
For example, is there a way to change the values in GuiDefaultProfile in game.cs? I tried this:
GuiDefaultProfile.fontType = Arial;
But no luck. Am I missing something simple?
For example, is there a way to change the values in GuiDefaultProfile in game.cs? I tried this:
GuiDefaultProfile.fontType = Arial;
But no luck. Am I missing something simple?
#2
Aun.
02/03/2007 (5:06 pm)
Have you tried using MLText and use something like this.%font = "<font:Tahoma Bold:16>" ;//change the font in MLText aMlText.setText(%font @ "HelloWorl");
Aun.
#3
Also, it causes unnecessary overhead in the engine, as it has to parse the font tag, and determine what to do -- which, from the posts I've read so far, she's looking at shaving off as many CPU cycles as she can due to hardware limitations.
02/03/2007 (9:16 pm)
@Aun, that should work, but causes a large amount of 'overhead' -- I've played Amanda's games before, and there's ALOT of text in them -- if the end-user wishes to change the font due to language issues, it would be best to change the profile all in all -- Also, it causes unnecessary overhead in the engine, as it has to parse the font tag, and determine what to do -- which, from the posts I've read so far, she's looking at shaving off as many CPU cycles as she can due to hardware limitations.
#4
02/15/2007 (2:49 pm)
It worked! Thanks much!!
Associate David Higgins
DPHCoders.com
if(isObject(GuiDefaultProfile)) GuiDefaultProfile.delete(); switch(%font_face) { case $FONTFACE_ARIAL: // definition for new profile with Arial break; case $FONTFACE_JAP: // definition with japanese font break; }That's more or less pseudo-code, but I'm sure you get the point -- you can see how profiles are done by looking at profile.cs, it checks to see if the profile exists first, and if not, creates it -- not sure if it uses isObject() or something else, a quick review should tell you though.
Any GUI objects that are currently loaded, that utilize the previously initialized profiles will be unaffected, you would have to unload and reload the GUI objects for the change to take effect.
The 'easiest' way to do this would be to have the user restart the application after making a notable change like that, and simply store the font preference in the prefs.cs -- this is done by prefexing the variable storing the value with $Pref:: (double check prefs.cs for validity -- TGB auto-saves all these variables in the prefs.cs)
You could, with the 'restart', method, just modify profiles.cs and simply refer to the variable that stores the font face value in the GuiDefaultProfile creation --
new GuiProfile(GuiDefaultProfile) { fontType = $Prefs::DefaultFontFace; // everything else };If you want to save them the horrible act of restarting the app, you could simply unload all relevant data and reload it -- this could become a time-consuming thing as you would pretty much be doing a 'soft-restart' of the application, or alot of code rewrites in how it handles all of this stuff (unloading all the guis and reloading them -- you'd have to unload ALL guis, including default ones loaded by TGB -- ie; MessageBox, ConsoleDlg, etc)
hope that helps