Need Help with Rotation around the cursor
Posted: Sat Aug 12, 2017 7:54 am
Hello, i am trying to create a little lua demo for my friend, and am currently trying to rotate an image around the mouse position. I tried just adding the mousex and mousey values to the origin, so they would be: "mousex + img:getWidth()/2" and "mousey + img:getHeight()/2"
But the origin is static and for some reason does not rotate with the image.
I'll post the .love here.
NVM, this board doesn't allow .lov files. Here's a zip instead.
Here's main.lua:
Any help would be appreciated a lot.
Thanks in advance,
unknowntrojan
But the origin is static and for some reason does not rotate with the image.
I'll post the .love here.
NVM, this board doesn't allow .lov files. Here's a zip instead.
Here's main.lua:
Code: Select all
function love.load()
angle = 0
scaley = 0.5
scalex = 0.5
width = love.graphics.getWidth()
height = love.graphics.getHeight()
posx = width/2
posy = height/2
img = love.graphics.newImage("test.jpg")
src = love.audio.newSource("test.mp3", "static")
mousey = 0
mousex = 0
angdegrees = 0
src:setVolume(1)
src:setPitch(1)
love.audio.play(src)
love.window.setTitle("Testing Build 25 Tech Demo.")
end
function love.draw()
love.graphics.setBackgroundColor(255, 152, 120, 255)
love.graphics.draw(img, posx, posy, angle, scalex, scaley, mousex + img:getWidth()/2, mousey + img:getHeight()/2) --HERE IT IS!
love.graphics.print("Angle:" .. angle, 0, 0)
love.graphics.print("Mouse X:" .. mousex, 0, 20)
love.graphics.print("Mouse Y:" .. mousey, 0, 40)
love.graphics.print("Angle in Degrees:" .. angdegrees, 0, 60)
love.graphics.print("Test Build Version 25", 200, 0)
end
function love.update(dt)
angle = angle + (dt*2) * math.pi / 2
if angle >= 600 then
angle = 0
end
mousey = love.mouse.getY()
mousex = love.mouse.getX()
angdegrees = angle / 0.02
end
Thanks in advance,
unknowntrojan