Rotate From Center
Posted: Thu May 31, 2012 3:02 am
I've been working on making a image rotate to face my mouse. After a while I finally got this to work, but I noticed something strange. I rotate it by doing this.
Where 'turtle' is a pre made image, turtlex is the x axis and turtley is the y axis of the image. angletomouse is the angle that the image rotates.
For whatever reason, the image is rotated by a corner, not the center of the image causing the image to look strange when rotating up close.
Here's the full script(This is a testing script so the variables won't make much sense with the pictures and such)
Code: Select all
function love.draw()
love.graphics.draw(turtle, turtlex, turtley, angletomouse, .1, .1)
--More code
end
For whatever reason, the image is rotated by a corner, not the center of the image causing the image to look strange when rotating up close.
Here's the full script(This is a testing script so the variables won't make much sense with the pictures and such)
Code: Select all
function love.load()
--Set a few basic stuff--
love.graphics.setBackgroundColor(50,50,50)
--Define a load of variables--
turtle = love.graphics.newImage("BLACK-MAGE.jpg")
turtlex = 50
turtley = 50
movespeed = 500
--Background music--
end
function love.update(dt)
--Sets mouse variables--
mousex = love.mouse.getX()
mousey = love.mouse.getY()
angletomouse = math.atan2(turtley-mousey,turtlex-mousex)
--Arrow keys--
if love.keyboard.isDown("right") then
turtlex = turtlex + (movespeed * dt)
elseif love.keyboard.isDown("left") then
turtlex = turtlex - (movespeed * dt)
end
if love.keyboard.isDown("down") then
turtley = turtley + (movespeed * dt)
elseif love.keyboard.isDown("up") then
turtley = turtley - (movespeed * dt)
end
--ASWD keys--
if love.keyboard.isDown("d") then
turtlex = turtlex + (movespeed * dt)
elseif love.keyboard.isDown("a") then
turtlex = turtlex - (movespeed * dt)
end
if love.keyboard.isDown("s") then
turtley = turtley + (movespeed * dt)
elseif love.keyboard.isDown("w") then
turtley = turtley - (movespeed * dt)
end
--Quit the game with esc--
if love.keyboard.isDown("escape") then
love.event.quit()
end
end
function love.draw()
--Draw the turtle--
love.graphics.draw(turtle, turtlex, turtley, angletomouse, .1, .1)
love.graphics.print(angletomouse, 250, 0)
--Redefine the player variable--
player = {xaxis=turtlex, yaxis=turtley, width=turtle:getWidth(), height=turtle:getHeight()}
love.graphics.setColor(255, 255, 255)
end