Page 1 of 1

Rotate text from the center point.

Posted: Sat Aug 23, 2014 3:57 pm
by MxMCube
Image

This is the code:

Code: Select all

  if badWords == true then
      love.graphics.setFont(epilepsyFont)
      epilepsy:draw(0, 0)
      love.graphics.printf("STOP SWEARING!!!1!!11", 0, height/2, width, "center")
  end
I want to rotate the text from the center point. How do I do that?

Re: Rotate text from the center point.

Posted: Sat Aug 23, 2014 4:27 pm
by davisdude
You have a couple options:
- Get the width and height of the text (Font:getWidth( 'Blah Blah' ), Font:getHeight( 'B' ) (note that for get height, if you test the largest letter, that's the only one that matters, so this will save some time))
- Then make those values the offset width and heights, and use your own values for rotation.
- Use the other values for love.graphics.print

Edit:
It would look a bit like this:

Code: Select all

local Fonts = {}

function NewFont( String, Font )
    local Index = #Fonts + 1
    local Width = Font:getWidth( String )
    local Height = Font:getHeight( 'A' ) -- This should do the trick, unless you use all lower-case, etc.

    local OffsetX = Width / 2
    local OffsetY = Height / 2

    Fonts[Index] = { String, x, y, 0, 1, 1, OffsetX, OffsetY }
    return Index
end

function SetPosition( Index, x, y )
    Fonts[Index][2] = x
    Fonts[Index][3] = y
end

function SetRotation( Index, Radians )
    Fonts[Index][4] = Radians
end

-- Make other functions for other things, like scale, etc.
function Draw( Index )
    love.graphics.print( Fonts[Index] )
end
This should work, but I can't guarantee it since I haven't tested it.

Re: Rotate text from the center point.

Posted: Sat Aug 23, 2014 5:47 pm
by MxMCube
Seems a bit difficult, but i'll see what I can do with the code. Thanks for the reply ;p