How do you rotate a drawable around a certain 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
User avatar
Audio
Prole
Posts: 2
Joined: Mon Mar 04, 2013 11:12 pm
Location: The center of the Earth

How do you rotate a drawable around a certain point?

Post by Audio »

Love2D rotates images around the upper-left corner of an image, What should I do to change the rotation point to somewhere else? Here are the important snippets in my code, since it's too long for you to read:

Code: Select all

function love.update(dt)
    Player.HeadRotation = math.atan2( love.mouse.getX() - Player.Position.x, Player.Position.y - love.mouse.getY() ) - math.pi / 2
end

love.draw()
    love.graphics.draw(PlayerImgHead, Player.Pos.x, Player.Pos.y, Player.HeadRotation)
end
The head rotates around a hinge at the upper left corner of the image, instead of rotating around my character's body.
User avatar
slime
Solid Snayke
Posts: 3172
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How do you rotate a drawable around a certain point?

Post by slime »

You can change the position and rotation origin of drawables with the ox and oy parameters to love.graphics.draw. For example, this will make the image rotate around and draw from its center, instead of the top left of the image:

Code: Select all

love.graphics.draw(PlayerImgHead, Player.Pos.x, Player.Pos.y, Player.HeadRotation, 1, 1, PlayerImgHead:getWidth()/2, PlayerImgHead:getHeight()/2)
User avatar
Audio
Prole
Posts: 2
Joined: Mon Mar 04, 2013 11:12 pm
Location: The center of the Earth

Re: How do you rotate a drawable around a certain point?

Post by Audio »

Thanks!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 6 guests