Difference between revisions of "love.graphics.setFont"

(Draw some text with custom font, 18px)
(Move example to the other example, fix typo and re-format code.)
(2 intermediate revisions by 2 users not shown)
Line 4: Line 4:
  
 
== Function ==
 
== Function ==
{{newin|[[0.7.0]]|070|type=variant}}
 
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
Line 13: Line 12:
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
== Examples ==
 
=== Draw some text with custom font, 18px ===
 
<source lang="lua">
 
function love.load()
 
Font = love.graphics.newFont("font.ttf",18)
 
end
 
 
function love.draw()
 
 
love.graohics.setFont(Font)
 
 
love.graphics.print("Hello World"!,0,0)
 
end
 
</source>
 
  
 
== Function ==
 
== Function ==
Line 59: Line 44:
 
function love.draw()
 
function love.draw()
 
love.graphics.print("Hello", 300, 300)
 
love.graphics.print("Hello", 300, 300)
 +
end
 +
</source>
 +
 +
=== Draw some text with custom font, 18px ===
 +
<source lang="lua">
 +
function love.load()
 +
    Font = love.graphics.newFont("font.ttf", 18)
 +
end
 +
 +
function love.draw()
 +
    love.graphics.setFont(Font)
 +
    love.graphics.print("Hello World", 0, 0)
 
end
 
end
 
</source>
 
</source>

Revision as of 08:47, 13 February 2015

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.

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

string filename
The filepath to the font.
number size (12)
The size of the font.

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.graphics.load()
  love.graphics.setFont(love.graphics.newFont(18))
end

function love.draw()
	love.graphics.print("Hello", 300, 300)
end

Draw some text with custom font, 18px

function love.load()
    Font = love.graphics.newFont("font.ttf", 18)
end

function love.draw()
    love.graphics.setFont(Font)
    love.graphics.print("Hello World", 0, 0)
end

See Also


Other Languages