Here's my current code, which will rotate an image around a pivot point specified relative to the image center:
Code: Select all
function Gem:draw(x, y, RGBTable, rotation, pivot_x, pivot_y)
love.graphics.push("all")
if RGBTable then love.graphics.setColor(RGBTable) end
love.graphics.translate(x or self.x, y or self.y)
if rotation then love.graphics.rotate(rotation) end
if pivot_x and pivot_y then love.graphics.translate(pivot_x, pivot_y) end
if rotation then love.graphics.rotate(-rotation) end
love.graphics.draw(
self.image,
self.quad,
pivot_x or 0,
pivot_y or 0,
rotation or 0,
1, -- scale x
1, -- scale y
self.width / 2, -- origin x
self.height / 2, -- origin y
0,
0
)
love.graphics.pop()
end
The first love.graphics.translate sets the x and y coordinates to draw the piece.
The first love.graphics.rotation sets the rotation for the piece.
The second love.graphics.translate... moves the x and y coordinates by the pivot distance (?)
The second rotation resets the rotation (???)
then in the draw function, the x and y coordinates are the pivot_x and pivot_y values because (???????)
I hope it's clear what I want to do, but what is a better way of doing this?