Font rotation & anchor point
Posted: Sun Jan 05, 2025 9:17 am
Hello,
I'm new to Love2D but have prior experience in other languages and frameworks. I'm trying to draw the individual characters of a string around a circle, with the baseline of each character pointing to the circle's center, at a specified radius (imagine a clock face with roman numerals).
After reading about Canvas transformations and pulling my hair out a bit, I've come up with this, which works fine:
I'm wondering if it's the best way to do it. Most of the time it'll be a background object, and calculating and redrawing it on every frame seems expensive. I don't have any issues yet since I'm just starting, but I'm curious about best practices.
Thanks for your help.
I'm new to Love2D but have prior experience in other languages and frameworks. I'm trying to draw the individual characters of a string around a circle, with the baseline of each character pointing to the circle's center, at a specified radius (imagine a clock face with roman numerals).
After reading about Canvas transformations and pulling my hair out a bit, I've come up with this, which works fine:
Code: Select all
function DrawString(letters, x, y, r)
love.graphics.push()
love.graphics.translate(x, y)
for i = 1, (#letters) do
local l = string.sub(letters, i, i)
local w = Font:getWidth(l) / 2 -- Font is defined globally
love.graphics.print(l, -w, -r * Screen.s) -- Screen.s adjusts for resolution scaling
love.graphics.rotate(math.pi * 2 / #letters)
end
love.graphics.pop()
end
Thanks for your help.