How do I center an image when moving
Posted: Sun Jan 05, 2020 8:55 pm
this is my code and I'm currently when I click somewhere on the screen it causes the top left-hand corner of the peng.png image to where the mouse pointer clicked when I want the bottom middle to go to where the screen was clicked, can anyone help?
P.S.
it wouldn't let me attach the music but it's at this link.
Code: Select all
function love.load()
peng = love.graphics.newImage("peng.png")
peng_x = 150
peng_y = 150
mouse_x, mouse_y = 150,150
music = love.audio.newSource("cp-coffee.mp3", "stream")
back = love.graphics.newImage("room.png")
end
function love.update(dt)
music:play()
if love.mouse.isDown(1) then
mouse_x, mouse_y = love.mouse.getPosition()
mouse_x = mouse_x - 5
mouse_y = mouse_y - 5
end
if mouse_x < peng_x then
peng_x = peng_x - (50 * 2.5 * dt)
end
if mouse_x > peng_x then
peng_x = peng_x + (50 * 2.5 * dt)
end
if mouse_y < peng_y then
peng_y = peng_y - (50 * 2.5 * dt)
end
if mouse_y > peng_y then
peng_y = peng_y + (50 * 2.5 * dt)
end
end
function love.draw()
love.graphics.draw(back, -1, 0, 0, 1.55)
love.graphics.draw(peng, peng_x, peng_y, 50.2, 0.1)
end
it wouldn't let me attach the music but it's at this link.