It's been a while to me on posting something on that forum that I also had to change my account, nevermind.
I got a little Math problem i guess with something that i couldn't figure out with research on that forum.
More about my issue, i was trying to do a simple following object on click that work pretty well (like in any
point and click), but when i wanted to add the angle about the click position something wrong happend.
More about the code:
Code: Select all
-- my object
user = { x = screen.w/8, y = screen.h/2 + screen.h/8, w=32, h=32, speed = 150, scale = 3, img = nil, angle = 0}
--mouse position
mpX = 0
mpY = 0
--my load function
function love.load(arg)
user.img = love.graphics.newImage('assets/2.png')
user.img:setFilter("nearest", "nearest", 0)
end
-- my update function
function love.update(dt)
if love.mouse.isDown(1) then
mpX = love.mouse.getX()
mpY = love.mouse.getY()
user.angle = math.pi/2 + math.atan2(mpY - (user.y + (user.h/2*user.scale)), mpX - (user.x + (user.w/2*user.scale)))
end
end
--my draw function
function love.draw(dt)
-- DRAW USER
love.graphics.setColor(1,1,1, 1)
-- problem with offset i guess!!
love.graphics.draw(user.img, user.x, user.y,user.angle,user.scale)
--test that ain't work
--love.graphics.draw(user.img, user.x, user.y,user.angle,user.scale,user.scale,user.w/2,user.h/2)
end
the final rendering (or position) of the object. I guess that it's more a math problem 'cause i try several combination
(as you could see on the attached zip of this post) and unfortunately none of them works. Hope i put
everything to be as clear as possible, so if anyone as a suggestion it 'll be very cool to solve this issue.
files: Thanks all in advance.