Is there a simple way to rotate an image?

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
HÄTE
Prole
Posts: 3
Joined: Sun Mar 06, 2011 8:36 am
Location: US

Is there a simple way to rotate an image?

Post by HÄTE »

Hi guys. I haven't used LÖVE in a while and I'm trying to get back into it. Right now I'm just testing out some of the basics again, but I can't seem to find a simple way to rotate an image (loaded using love.graphics.newImage). I looked at the Wiki and a few libraries and stuff, but things like love.physics or an entire animation library seem a little complicated for something like this. I messed around with love.graphics.drawq a bit, but can't seem to make it rotate around the center of the image (it rotates around the upper left it seems). Is there something obvious and easier that I'm missing here, or should I just use one of the above-mentioned methods?
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Is there a simple way to rotate an image?

Post by tentus »

Rotating is done from the top left, but you can offset the position AND rotation using the last two parameters.
love.graphics.draw

So, if you've got a 50 by 50 pixel image called img that you want drawn (from the center) at 200x200 at .5 radians (about 30 degrees), the code would look like this:

Code: Select all

love.graphics.draw(img, 200, 200, .5, 1, 1, 25, 25)
The 1s are the scale parameters, in this example we are not scaling up or down.
Kurosuke needs beta testers
User avatar
HÄTE
Prole
Posts: 3
Joined: Sun Mar 06, 2011 8:36 am
Location: US

Re: Is there a simple way to rotate an image?

Post by HÄTE »

Awesome, thanks. Not really sure how I missed this the first time around. :roll:
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 0 guests