Hi,
I'm new here and I'm poking around love2d a little. I'm interested if there's a way to print text to the left of the origin point. I have tried using printf and aligned text to the right, but it's still required to define offset and box and it's annoying to recalculate bounding box if the text is dynamic.
To the point. I want to have text in the top right and top left corners of my game, and if I set position of print to (gameWidth, 0) text goes out of rendering area.
I didn't find anything in the documentation about it. Is there maybe some trick to it?
Set origin for text rendering
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Set origin for text rendering
There are two options, both of which involve getting the width:
See here for more.
Code: Select all
local font = love.graphics.getFont() -- No need to do this unless you're using default font
local width = font:getWidth( text )
-- Method 1 (not as clean, IMHO)
love.graphics.print( text, GameWidth - width, 0 ) -- Maybe have -2 or something for padding
-- Method 2
love.graphics.print( text, GameWidth, 0, 0, 1, 1, width, 0 ) -- Also could use padding
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Set origin for text rendering
Use printf with x=0, full width of the screen and align right.
When I write def I mean function.
Re: Set origin for text rendering
So, you can't just switch origin point? Shame. I like @kikito 's solution. Much simpler than calculating font length. Although I might get into some trouble when rendering UI with a background. I guess long term solution would be calculating font length for more complicated layouts.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Set origin for text rendering
On a ui, you can use the with and left corner of the "container of the text" (text box, window, etc). The effect should be the same.
When I write def I mean function.
Who is online
Users browsing this forum: Google [Bot] and 2 guests