Difference between revisions of "love.graphics.newFont"

(Realtime information addition)
Line 1: Line 1:
Creates a new [[Font]]. Created fonts are not cached, in that calling this function with the same arguments will always create a new Font object.
+
Creates a new [[Font]] from a TrueType Font or BMFont file. Created fonts are not cached, in that calling this function with the same arguments will always create a new Font object.
 +
 
 +
All variants which accept a filename can also accept a [[Data]] object instead.
 +
 
 
{{newobjectnotice}}
 
{{newobjectnotice}}
 
== Function ==
 
== Function ==
 +
Create a new BMFont or TrueType font.
 +
=== Synopsis ===
 +
<source lang="lua">
 +
font = love.graphics.newFont( filename )
 +
</source>
 +
=== Arguments ===
 +
{{param|string|filename|The filepath to the BMFont or TrueType font file.}}
 +
=== Returns ===
 +
{{param|Font|font|A Font object which can be used to draw text on screen.}}
 +
=== Notes ===
 +
If the file is a TrueType font, it will be size 12. Use the variant below to create a TrueType font with a custom size.
 +
 +
== Function ==
 +
Create a new TrueType font.
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Line 7: Line 24:
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|string|filename|The filepath to the font file.}}
+
{{param|string|filename|The filepath to the TrueType font file.}}
{{param|number|size (12)|The size of the font in pixels.}}
+
{{param|number|size|The size of the font in pixels.}}
 
=== Returns ===
 
=== Returns ===
 
{{param|Font|font|A Font object which can be used to draw text on screen.}}
 
{{param|Font|font|A Font object which can be used to draw text on screen.}}
 +
 
== Function ==
 
== Function ==
 +
Create a new BMFont.
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
font = love.graphics.newFont( data, size )
+
font = love.graphics.newFont( filename, imagefilename )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|Data|data|The encoded data to decode into a font.}}
+
{{param|string|filename|The filepath to the BMFont file.}}
{{param|number|size (12)|The size of the font in pixels.}}
+
{{param|string|imagefilename|The filepath to the BMFont's image file. If this argument is omitted, the path specified inside the BMFont file will be used.}}
 
=== Returns ===
 
=== Returns ===
 
{{param|Font|font|A Font object which can be used to draw text on screen.}}
 
{{param|Font|font|A Font object which can be used to draw text on screen.}}
 +
 
== Function ==
 
== Function ==
This variant uses the default font (Vera Sans) with a custom size.
+
Create a new instance of the default font (Vera Sans) with a custom size.
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Line 52: Line 72:
 
[[Category:Functions]]
 
[[Category:Functions]]
 
[[Sub-Category::Object Creation| ]]
 
[[Sub-Category::Object Creation| ]]
{{#set:Description=Creates a new [[Font]].}}
+
{{#set:Description=Creates a new [[Font]] from a TrueType Font or BMFont file.}}
 
{{#set:Since=000}}
 
{{#set:Since=000}}
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|love.graphics.newFont}}
 
{{i18n|love.graphics.newFont}}

Revision as of 16:41, 24 April 2017

Creates a new Font from a TrueType Font or BMFont file. Created fonts are not cached, in that calling this function with the same arguments will always create a new Font object.

All variants which accept a filename can also accept a Data object instead.


O.png This function can be slow if it is called repeatedly, such as from love.update or love.draw. If you need to use a specific resource often, create it once and store it somewhere it can be reused!  



Function

Create a new BMFont or TrueType font.

Synopsis

font = love.graphics.newFont( filename )

Arguments

string filename
The filepath to the BMFont or TrueType font file.

Returns

Font font
A Font object which can be used to draw text on screen.

Notes

If the file is a TrueType font, it will be size 12. Use the variant below to create a TrueType font with a custom size.

Function

Create a new TrueType font.

Synopsis

font = love.graphics.newFont( filename, size )

Arguments

string filename
The filepath to the TrueType font file.
number size
The size of the font in pixels.

Returns

Font font
A Font object which can be used to draw text on screen.

Function

Create a new BMFont.

Synopsis

font = love.graphics.newFont( filename, imagefilename )

Arguments

string filename
The filepath to the BMFont file.
string imagefilename
The filepath to the BMFont's image file. If this argument is omitted, the path specified inside the BMFont file will be used.

Returns

Font font
A Font object which can be used to draw text on screen.

Function

Create a new instance of the default font (Vera Sans) with a custom size.

Synopsis

font = love.graphics.newFont( size )

Arguments

number size (12)
The size of the font in pixels.

Returns

Font font
A Font object which can be used to draw text on screen.

Examples

Use newFont to draw a custom styled text

-- load ttf file font. set 20px font-size
mainFont = love.graphics.newFont("anyfont.ttf", 20);

function love.draw() 
	-- set font before draw text
	love.graphics.setFont(mainFont);
	-- draw text "Hello world!" at left: 100, top: 200
	love.graphics.print("Hello world!", 100, 200);
end;

See Also


Other Languages