Difference between revisions of "Legacy:LoadFont"

From Spherical
Jump to: navigation, search
(created from http://web.archive.org/web/20120505210614/http://www.spheredev.org/wiki/LoadFont)
 
(filled)
 
Line 1: Line 1:
 
 
 
Loads a Sphere [[API:Font|font]] from a file.
 
Loads a Sphere [[API:Font|font]] from a file.
  
Line 6: Line 4:
  
 
==Usage==
 
==Usage==
{{Usage|returns=[[API:Font|Font]]|object={{{object}}}|func=LoadFont|params=filename}}
+
{{Usage|returns=[[API:Font|Font]]|func=LoadFont|params=filename}}
  
* '''param1''' type. param1 description
+
* '''filename''' string. Filename of the font to load, relative to the project's {{dir|fonts}} subdirectory
* '''param2''' type. param2 description
 
* '''paramN''' type. paramN description
 
  
 
==Examples==
 
==Examples==
(examples with syntaxhighlighted code)
+
The following example will show the text using the font {{path|myfont.rfn}}, inside the game's {{dir|fonts}} subdirectory (the font file must exist first):
 +
<syntaxhighlight>
 +
var f = LoadFont("myfont.rfn");
 +
f.drawText(100, 80, "This text is drawn with a font.");
 +
FlipScreen();
 +
GetKey();
 +
</syntaxhighlight>
  
 
==Notes==
 
==Notes==
(notes)
+
* To load fonts in subdirectories other than {{dir|fonts}}, use one of the following prefixes, followed by the desired path:
 +
** {{dir|~/}} to load from the game's base directory. This allows for better organisation.
 +
** {{dir|/common/}} to load from {{dir|Sphere/common/}}, a directory that can be shared by all games.
 +
* If text needs to be displayed, but the font style isn't important, consider the alternative function [[API:GetSystemFont|GetSystemFont]]().
  
 
==See also==
 
==See also==
* see also
+
* Sphere [[API:Font|Font]] object
* see also
+
* [[API:Font/drawText|Font.drawText]]()
* see also
+
* [[API:GetSystemFont|GetSystemFont]]()
* etc
+
* [[API:FlipScreen|FlipScreen]]()
 +
* [[API:GetKey|GetKey]]()
  
 
{{API:Font/navbox}}
 
{{API:Font/navbox}}

Latest revision as of 00:22, 25 June 2013

Loads a Sphere font from a file.

Usage

Font LoadFont(filename);


  • filename string. Filename of the font to load, relative to the project's fonts subdirectory

Examples

The following example will show the text using the font myfont.rfn, inside the game's fonts subdirectory (the font file must exist first):

var f = LoadFont("myfont.rfn");
f.drawText(100, 80, "This text is drawn with a font.");
FlipScreen();
GetKey();

Notes

  • To load fonts in subdirectories other than fonts, use one of the following prefixes, followed by the desired path:
    • ~/ to load from the game's base directory. This allows for better organisation.
    • /common/ to load from Sphere/common/, a directory that can be shared by all games.
  • If text needs to be displayed, but the font style isn't important, consider the alternative function GetSystemFont().

See also

API:Font/navbox