Rotating an image on its center
Posted: Thu Jun 02, 2022 3:16 pm
Hello,
I drew an image and rotated it by increasing its rotation by 1 degree converted in radians every second, or at least that's what I think I am doing feel free to correct me on that if I am wrong
Here's my code for that so that you can see better :
So with that the image rotates around its top-left corner (it goes off the screen when over, under and to the left of its original position however does not go that far when to the right, stays visible), even though I drew it with with its x and y origins being at its center.
Also it rotates far from it, like I drew the rectangular hitbox and a small circle at the center and it is shwown and rotates at a distance way outside of it, and I don't know why
I drew an image and rotated it by increasing its rotation by 1 degree converted in radians every second, or at least that's what I think I am doing feel free to correct me on that if I am wrong
Here's my code for that so that you can see better :
Code: Select all
local data = {}
function love.load()
data.sprite = love.graphics.newImage("Lizard.png")
data.width = data.sprite:getWidth()
data.height = data.sprite:getHeight()
data.x = love.graphics.getWidth() / 2 - data.width / 2
data.y = love.graphics.getHeight() / 2 - data.height / 2
data.rotation = math.rad(0)
data.scaleX = 1
data.scaleY = 1
data.originX = data.x + data.width / 2
data.originY = data.y + data.height / 2
end
function love.update(dt)
data.rotation = data.rotation + 1 * dt
end
function love.draw()
love.graphics.setColor(1, 1, 1)
love.graphics.draw(data.sprite, data.x, data.y, data.rotation, data.scaleX, data.scaleY, data.originX, data.originY)
-- Rectangle Hitbox
love.graphics.rectangle('line', data.x, data.y, data.width, data.height)
-- Center
love.graphics.circle('fill', data.x + data.width / 2, data.y + data.height / 2, 4)
end
Also it rotates far from it, like I drew the rectangular hitbox and a small circle at the center and it is shwown and rotates at a distance way outside of it, and I don't know why