Difference between revisions of "love.graphics.setFont"
m (→Examples: Some fixing.) |
|||
(11 intermediate revisions by 6 users not shown) | |||
Line 12: | Line 12: | ||
=== Returns === | === Returns === | ||
Nothing. | Nothing. | ||
+ | |||
== Function == | == Function == | ||
− | {{oldin|[[0.8.0]]|type=variant}} | + | {{oldin|[[0.8.0]]|080|type=variant}} |
=== Synopsis === | === Synopsis === | ||
<source lang="lua"> | <source lang="lua"> | ||
Line 24: | Line 25: | ||
Nothing. | Nothing. | ||
== Function == | == Function == | ||
− | {{oldin|[[0.8.0]]|type=variant}} | + | {{oldin|[[0.8.0]]|080|type=variant}} |
This variant creates a new font using the default font and the size specified, and sets it as the current font. '''Do not use this function in [[love.update]] or [[love.draw]].''' That would create a new font every frame, eating up memory very quickly. | This variant creates a new font using the default font and the size specified, and sets it as the current font. '''Do not use this function in [[love.update]] or [[love.draw]].''' That would create a new font every frame, eating up memory very quickly. | ||
=== Synopsis === | === Synopsis === | ||
Line 37: | Line 38: | ||
=== Draw some text with default font, 18px === | === Draw some text with default font, 18px === | ||
<source lang="lua"> | <source lang="lua"> | ||
− | love.graphics.setFont(18) | + | function love.load() |
+ | font = love.graphics.newFont(18) | ||
+ | end | ||
+ | |||
+ | function love.draw() | ||
+ | love.graphics.setFont(font) | ||
+ | love.graphics.print("Hello, World!", 200, 100) | ||
+ | end | ||
+ | </source> | ||
+ | |||
+ | === Draw some text with custom font, 18px === | ||
+ | <source lang="lua"> | ||
+ | function love.load() | ||
+ | font = love.graphics.newFont("MyFont.ttf", 18) | ||
+ | end | ||
function love.draw() | function love.draw() | ||
− | love.graphics.print("Hello", | + | love.graphics.setFont(font) |
+ | love.graphics.print("Hello, World!", 200, 100) | ||
end | end | ||
</source> | </source> | ||
+ | |||
== See Also == | == See Also == | ||
* [[parent::love.graphics]] | * [[parent::love.graphics]] | ||
* [[love.graphics.newFont]] | * [[love.graphics.newFont]] | ||
* [[love.graphics.getFont]] | * [[love.graphics.getFont]] | ||
+ | * [[love.graphics.setNewFont]] | ||
[[Category:Functions]] | [[Category:Functions]] | ||
{{#set:Description=Set an already-loaded Font as the current font.}} | {{#set:Description=Set an already-loaded Font as the current font.}} | ||
{{#set:Since=000}} | {{#set:Since=000}} | ||
+ | {{#set:Sub-Category=State}} | ||
== Other Languages == | == Other Languages == | ||
{{i18n|love.graphics.setFont}} | {{i18n|love.graphics.setFont}} |
Latest revision as of 01:36, 1 September 2022
Set an already-loaded Font as the current font or create and load a new one from the file and size.
It's recommended that Font objects are created with love.graphics.newFont in the loading stage and then passed to this function in the drawing stage.
Contents
Function
Synopsis
love.graphics.setFont( font )
Arguments
Font font
- The Font object to use.
Returns
Nothing.
Function
Removed in LÖVE 0.8.0 |
This variant is not supported in that and later versions. |
Synopsis
love.graphics.setFont( filename, size )
Arguments
Returns
Nothing.
Function
Removed in LÖVE 0.8.0 |
This variant is not supported in that and later versions. |
This variant creates a new font using the default font and the size specified, and sets it as the current font. Do not use this function in love.update or love.draw. That would create a new font every frame, eating up memory very quickly.
Synopsis
love.graphics.setFont( size )
Arguments
number size (12)
- The size of the font.
Returns
Nothing.
Examples
Draw some text with default font, 18px
function love.load()
font = love.graphics.newFont(18)
end
function love.draw()
love.graphics.setFont(font)
love.graphics.print("Hello, World!", 200, 100)
end
Draw some text with custom font, 18px
function love.load()
font = love.graphics.newFont("MyFont.ttf", 18)
end
function love.draw()
love.graphics.setFont(font)
love.graphics.print("Hello, World!", 200, 100)
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info