Rotate text from the center point.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
MxMCube
Prole
Posts: 8
Joined: Thu Aug 21, 2014 11:56 pm

Rotate text from the center point.

Post 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?
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Rotate text from the center point.

Post 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.
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
MxMCube
Prole
Posts: 8
Joined: Thu Aug 21, 2014 11:56 pm

Re: Rotate text from the center point.

Post by MxMCube »

Seems a bit difficult, but i'll see what I can do with the code. Thanks for the reply ;p
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests