I'm new in here and I just started messing arround with Löve, so I'll just come straight to my question:
How can I get the x- and y-position of an Image object.
do I have to convert this to an ImageData to get the positions, or is there a function with the Image Type
the actual thing I want to do is get my player facing the mouse position.
I know, that I have to use the atan2 function to do that - also the search couldnt solve my problem so far
so what I'm doing:
First I'm loading the image and get the start positions:
Code: Select all
function love.load()
player = love.graphics.newImage("gfx/player.png")
x = 400
y = 300
end
Code: Select all
function love.update(dt)
mousex = love.mouse.getX()
mousey = love.mouse.getY()
-- x = current x position of the Image
-- y = current y position of the Image
angle = math.atan2(mousey-y,mousex-x)
if love.keyboard.isDown("w") then
y = y - 5
end
if love.keyboard.isDown("s") then
y = y + 5
end
if love.keyboard.isDown("d") then
x = x + 5
end
if love.keyboard.isDown("a") then
x = x - 5
end
end