Page 1 of 1

Rotate an Image

Posted: Wed Sep 22, 2010 4:47 pm
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

Re: Rotate an Image

Posted: Wed Sep 22, 2010 5:21 pm
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)

Re: Rotate an Image

Posted: Wed Sep 22, 2010 5:24 pm
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)

Re: Rotate an Image

Posted: Wed Sep 22, 2010 5:26 pm
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)

Re: Rotate an Image

Posted: Sat Oct 02, 2010 8:35 am
by rude
Shouldn't that be math.rad(90)?

Re: Rotate an Image

Posted: Sat Oct 02, 2010 11:53 pm
by kikito
If up has to become down and viceversa, then I think that's 180 degrees, not 90

Re: Rotate an Image

Posted: Sun Oct 03, 2010 12:02 am
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)

Re: Rotate an Image

Posted: Sun Oct 03, 2010 12:15 am
by TechnoCat
I feel like a bumbling idiot looking back at my posts.

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

Scaling:
-1