dragable delay

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
daegan
Prole
Posts: 4
Joined: Mon Dec 09, 2024 9:16 pm

dragable delay

Post by daegan »

hey, complete beginer in coding and game making here. i managed to make a dragable rectange but it's pretty delayed, this results in the mouse going out of the rectange wich makes the mouse stop moving it. have any tips? thanks!

also the code is pretty messy since im adding other thing as well, sorry...
Attachments
move thingy.love
(1.74 KiB) Downloaded 374 times
User avatar
Hugues Ross
Party member
Posts: 112
Joined: Fri Oct 22, 2021 9:18 pm
Location: Quebec
Contact:

Re: dragable delay

Post by Hugues Ross »

Well, for starters you don't need to disable rect.indrag when the mouse goes outside the rectangle. That way, the only way for a drag the user has started to end is when they let go of the mouse button. If you're making a game where the drag can be cancelled by the box being prevented from reaching the mouse (ie. walls restricting where the box can go) I'd still use a different check, probably something like a raycast to see if the box can reach the mouse or not.

Anyway, I'm no expert on this subject but I think the reason the drag hangs behind the mouse is that the logic & rendering of the game are happening independently of your OS receiving hardware events and your GPU rendering a hardware cursor. Which makes sense--you wouldn't want your entire computer tied to a game's framerate. In theory, you could 'fix' this visually (the drag issue you're having wouldn't change) by hiding the mouse and rendering your own cursor at the position love reports the mouse being at...not sure if that's really an ideal solution and I probably wouldn't bother, but I'm pretty sure that'd work.
daegan
Prole
Posts: 4
Joined: Mon Dec 09, 2024 9:16 pm

Re: dragable delay

Post by daegan »

Hugues Ross wrote: Wed Dec 11, 2024 1:03 am Well, for starters you don't need to disable rect.indrag when the mouse goes outside the rectangle. That way, the only way for a drag the user has started to end is when they let go of the mouse button. If you're making a game where the drag can be cancelled by the box being prevented from reaching the mouse (ie. walls restricting where the box can go) I'd still use a different check, probably something like a raycast to see if the box can reach the mouse or not.

Anyway, I'm no expert on this subject but I think the reason the drag hangs behind the mouse is that the logic & rendering of the game are happening independently of your OS receiving hardware events and your GPU rendering a hardware cursor. Which makes sense--you wouldn't want your entire computer tied to a game's framerate. In theory, you could 'fix' this visually (the drag issue you're having wouldn't change) by hiding the mouse and rendering your own cursor at the position love reports the mouse being at...not sure if that's really an ideal solution and I probably wouldn't bother, but I'm pretty sure that'd work.

hey, thanks! i'll see if i can fix it. the delay doesn't matter that much but it would be pretty fun to try drawing a cursor where the game thinks it is, might do that just for fun :crazy:
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 11 guests