Question: How do I use the print function in Love2D?


In Love2D, the print function is used for printing text to the console, which is helpful for debugging purposes. However, if you want to display text within the window of your game or application, you will need to use the graphics library provided by Love2D, specifically the function.

Here's an example of how you can draw text on the screen:

function love.draw() -- Sets the default font with size 14, 1, 1) -- Sets the color to white"Hello, World!", 400, 300) end

In this example:

  • sets the current font. If you don't set a font, Love2D uses the default font with a default size.
  • is setting the color of the text. The values are in the range [0, 1] for Red, Green, Blue, and optionally Alpha (transparency).
  • takes the string to print and the x and y coordinates where it should be drawn on the screen.

The function has more advanced uses where you can specify additional parameters such as the angle of rotation, scale factors, and more. Here's an example demonstrating these optional parameters:

function love.draw() local x, y = 400, 300 local text = "Rotated Text" local angle = math.pi / 4 -- 45 degrees, x, y, angle) end

In this extended example, the text "Rotated Text" is drawn at a 45-degree angle. The x and y variables are still controlling the position, but now we also pass angle to rotate the text.

For even more control over the appearance of text, you can create a Text object using, which allows for efficient rendering of static text.

function love.load() local font = myText =, "Hello, World!") end function love.draw(), 400, 300) end

This technique is especially useful when dealing with text that doesn't change frequently, as it avoids the overhead of generating the text image each frame.

These are some of the basic ways to use the print functionality in Love2D to draw text onto the game window.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.