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
Fr3@k
Prole
Posts: 1
Joined: Wed Sep 22, 2010 4:42 pm

Rotate an Image

Post by Fr3@k »

Hey,
i want just to rotate an image but i only was sucessful to rotate the image around a point... :x
i want it to rotate itself. do you know what i mean?

e.g.:

Code: Select all

____Up____
|---------|
____Down__
to

Code: Select all

____Down__
|---------|
____Up____
(This is an Image :P)
Any idea?

EDIT///
And one question:
Is löve just a language for "minigames" or is it possible to create complex games with it?

MFG
Fr3@k

PS.:
Sorry for my Englisch ;)
<-- German :P
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Rotate an Image

Post by TechnoCat »

love.graphics.draw( drawable, x, y, r, sx, sy, ox, oy )

The r in the function is the rotation om radians.

Code: Select all

love.graphics.draw(image,x,y,math.pi)
Or if you are trying to flip the image without rotating, use the scale parameters.

Code: Select all

love.graphics.draw(image,x,y,0,1,-1)
Last edited by TechnoCat on Wed Sep 22, 2010 5:26 pm, edited 2 times in total.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Rotate an Image

Post by nevon »

Löve is a game development framework. Lua is the language used. And sure, you can make complex games using Löve, if you have the skills.

To rotate an image around itself, you have to set the horizontal and vertical offsets to half the image's width/height. So if you have an image that's 32px wide and 64px tall, and you want to rotate it 90 degrees "around itself" you'd do:

Code: Select all

love.graphics.draw(image, X, Y, math.deg(90), 1, 1, 16, 32)
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Rotate an Image

Post by TechnoCat »

nevon wrote:To rotate an image around itself, you have to set the horizontal and vertical offsets to half the image's width/height. So if you have an image that's 32px wide and 64px tall, and you want to rotate it 90 degrees "around itself" you'd do:

Code: Select all

love.graphics.draw(image, X, Y, math.deg(90), 1, 1, 16, 32)
This can be even further elaborated with

Code: Select all

love.graphics.draw(image, X, Y, math.deg(90), 1, 1, image:getWidth()/2, image:getHeight()/2)
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Rotate an Image

Post by rude »

Shouldn't that be math.rad(90)?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Rotate an Image

Post by kikito »

If up has to become down and viceversa, then I think that's 180 degrees, not 90
When I write def I mean function.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Rotate an Image

Post by Robin »

I don't think you're all helping the poor fellow understand all this.

What TechnoCat said first is the best way, I think:
TechnoCat wrote:love.graphics.draw( drawable, x, y, r, sx, sy, ox, oy )

The r in the function is the rotation om radians.

Code: Select all

love.graphics.draw(image,x,y,math.pi)
Or if you are trying to flip the image without rotating, use the scale parameters.

Code: Select all

love.graphics.draw(image,x,y,0,1,-1)
Help us help you: attach a .love.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: Rotate an Image

Post by TechnoCat »

I feel like a bumbling idiot looking back at my posts.

Rotating:
math.rad(180) = math.pi

Scaling:
-1
Post Reply

Who is online

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