Rotating images doesn't rotate the 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
togFox
Party member
Posts: 832
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Rotating images doesn't rotate the image

Post by togFox »

Image

In the image above - the image on the right is drawn with zero rotation and draws as expected:

Code: Select all

v.rotation = 0              -- radians
love.graphics.draw(IMAGE[v.imagetype], v.x, v.y, v.rotation, 1, 1, 0,0)
I use the mouse to do bounding box so it has a 'click zone' that works well and everything is good.

The image on the left is rotated by 90 degrees:

Code: Select all

v.rotation = math.pi / 2              -- 90 degrees clockwise expressed as radians
love.graphics.draw(IMAGE[v.imagetype], v.x, v.y, v.rotation, 1, 1, 0,0)
It draws correctly as the image is rotated by the upper left corner - as per normal but I was expecting the bounding box for this image to also rotate but it does not. The bounding box remains as per the unrotated image and is highlighted by the blue box I added to the image.

How do I rotate/transform the image dimensions so that it really rotates and is not just appear to rotate. If I can do that then my bounding box mouse clicks will start to work as expected.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
User avatar
darkfrei
Party member
Posts: 1216
Joined: Sat Feb 08, 2020 11:09 pm

Re: Rotating images doesn't rotate the image

Post by darkfrei »

Use the ox, oy as offset to the middle of your picture:

Code: Select all

love.graphics.draw( drawable, x, y, r, sx, sy, ox, oy, kx, ky )
https://love2d.org/wiki/love.graphics.draw
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
togFox
Party member
Posts: 832
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Rotating images doesn't rotate the image

Post by togFox »

That will shift the drawn image but won't rotate my 'click' zone.

I think I'm going to have to do some run time translation on the click zone based on the rotation of the image before doing a bounding box check.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
User avatar
togFox
Party member
Posts: 832
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Rotating images doesn't rotate the image

Post by togFox »

Can someone confirm: rotating the image during love.graphics.draw does not change the values of image:getWidth() and image:getHeight()?
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
User avatar
BrotSagtMist
Party member
Posts: 665
Joined: Fri Aug 06, 2021 10:30 pm

Re: Rotating images doesn't rotate the image

Post by BrotSagtMist »

Of course it does not, what gave you that idea to begin with?
Draw draws data not changing it, getSomething gets a value from that data, which of course has not been changed.
And we have no idea where your bounding box actually comes from, you left that code out.
obey
Post Reply

Who is online

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