Hi, i wanted to create mouse dragging for a project of mine called dogboxing.
but, i keep having issues, like this problem, when the mouse is stuck with the dragged thing
can you help me?
Mouse dragging
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Mouse dragging
- Attachments
-
- dragging.love
- (406 Bytes) Downloaded 274 times
Re: Mouse dragging
Your problem is that you never check if the mouse is released, so dactive is always true. Consider adding an else statement to the love.mouse.isdown check to set dactive to false.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: Mouse dragging
I think the issue is a confusion about when to do what.
You need to capture the coordinate difference only when the mouse button goes down, not every frame while it's pressed. The easy way is to use the love.mousepressed event for that.
Then, while the mouse button is pressed, you move the shape.
You need to capture the coordinate difference only when the mouse button goes down, not every frame while it's pressed. The easy way is to use the love.mousepressed event for that.
Code: Select all
function love.mousepressed(mx, my, b)
if b == 1 then
diffx = mx - x
diffy = my - y
end
end
Code: Select all
function love.update(dt)
if love.mouse.isDown(1) then
mx, my = love.mouse.getPosition()
x = mx - diffx
y = my - diffy
end
end
Re: Mouse dragging
Thanks, now it works.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests