In Love2D, the
Here's an example of how you can draw text on the screen:
In this example:
love.graphics.setFont sets the current font. If you don't set a font, Love2D uses the default font with a default size.
love.graphics.setColor is setting the color of the text. The values are in the range [0, 1] for Red, Green, Blue, and optionally Alpha (transparency).
love.graphics.print takes the string to print and the x and y coordinates where it should be drawn on the screen.
love.graphics.print 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:
In this extended example, the text
"Rotated Text" is drawn at a 45-degree angle. The
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
love.graphics.newText, which allows for efficient rendering of static text.
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.